For a 4-D array, I'm trying to average the values using compact pointer notation. Using examples from my text, it says I can use something like this:
void DisplayAverage(double (*set)[DIM1][DIM2][DIM3])
double *ptr;
double subTotal2 = 0;
for (ptr = (double *)set; ptr < (double *)set + DIM0 * DIM1 * DIM2 * DIM3; ptr++) {
su...
Hi,
I've written a small program for my programming class, that uses pointers to reverse a char array. I was wondering if there is anything that I should do differently? Am I doing this correctly? Is there a more efficient way to accomplish this? Thanks!
My small program:
int main ( )
{
char buffer[80];
PrintHeader();
cout << "\nStr...
NSDecimalNumber *lat = [[NSDecimalNumber alloc]initWithDouble:sqlite3_column_double(selectStatement, 1)];
[latt addObject:lat];
[lat release];
CLLocationCoordinate2D annot;
annot.latitude = [[latt objectAtIndex:k]doubleValue];
The above 2 codes shows the creation and retrieving of double valu...
In C++ for any data type I can do the following:
Type* typedPointer = obtain();
void* voidPointer = typedPointer;
which cast is performed when I assign Type* to void*? Is this the same as
Type* typedPointer = obtain();
void* voidPointer = reinterpret_cast<void*>( typedPointer );
or is it some other cast?
...
I know that we have different pointers like int, float, and char. A void pointer is the only pointer which can hold all others.
Do the other pointers exist only for the flexibility to do pointer arithmetic?
Is there any other reason that pointers other than void are present in C language?
...
I am trying to build a program to Tolkinize a string (i'm trying to do this with out using the string class - so as to learn more about pointers and how chars work) - I have built a program that i think works (any suggestions would be great!) When i tried to compile the program I get these random errors:
Error 1 error LNK2019: unreso...
Is the following conversion safe?
int b[10][10];
char *x;
int a[]={0,1,2,3,4,5,6,7,8,9};
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
b[i][j]=a[i];
for(x=(char *)&b[0];x<=(char *)&b[9][9];x+=sizeof(a+1)) // Problem lies here!
printf("%d\n",*x);
I don't think the above conversion in the for loop is safe (I think it is platfo...
Hi there, I'm writing a string tokenization program for a homework assignment in C++, that uses pointers. However, when I run & debug it, it says that my pointer pStart, is invalid. I have a feeling that my problem resides in my param'ed constructor, I've included both the constructor and the object creation below.
I would appreciate it...
I'm trying to make a Trie data structure (school work) and I'm using a list which I've also made myself and works fine (tested) to store the N-nodes in the Trie.
Anyway, the problem is, every node is supposed to store a list of nodes so I can make my N-ary tree/trie but I've hit a snag...
When I'm debugging and going through the for lo...
I'm learning C++ at the moment and though I grasp the concept of pointers and references for the better part, some things are unclear.
Say I have the following code (assume Rectangle is valid, the actual code is not important):
#include <iostream>
#include "Rectangle.h"
void changestuff(Rectangle& rec);
int main()
{
Rectangle rect...
I am following this tutorial (http://theocacao.com/document.page/234). I am confused about this paragraph, mainly the lines relating to calloc:
We can also use a variation of the malloc function, called calloc. The calloc function takes two arguments, a value count and the base value size. It also clears the memory before returning a...
So here's what I have so far:
void sortArray(int amountOfScores, int* testScores)
{
for(int i = 0; i < amountOfScores; i++)
{
for(int j = 0; j < amountOfScores-1; j++)
{
if(*(testScores+i) > *(testScores+j+1))
{
int temp = *(testScores+j);
*(testScores+j) = ...
How can you use circular #import to strongly typed objects in objective-c
I have an audio controller class, a menu class and a gameview class.
The application delegate sets up these classes and assigns a pointers so:
the menu class is aware of the audio and gameview class
the gameview class has a reference to the audio and menu class
...
Hi, I'm a programming student trying to better understand pointers, one of the things I learned is that you can set a pointer to NULL. My question is, what's the difference between these two statements? When would each of them return true/false?
if (some_ptr == NULL)
if (*some_ptr == NULL)
Thanks!
...
Hi,
I've written a simple string tokenizing program using pointers for a recent school project. However, I'm having trouble with my StringTokenizer::Next() method, which, when called, is supposed to return a pointer to the first letter of the next word in the char array. I get no compile-time errors, but I get a runtime error which stat...
Hi,
as its legal to convert a pointer to non-const to a pointer to a const..
similarly,why isnt it legal to convert (pointer to pointer to non-const) to a (pointer to pointer to a const)
i.e,
char *s1 = 0;
const char *s2 = s1; // OK...
char *a[MAX]; // aka char **
const char **ps = a; // error!
Thanks.
...
Hi,
tl;dr - Could you please expand on the 4 comments in the first code snippet below? Specifically what is meant be deref
I'm a long time Java developer looking to learn C++. I came across this website aimed at developers in my situation.
int x, *p, *q;
p = new int;
cin >> x;
if (x > 0) q = &x;
*q = 3; ...
How do you use a pointer-to-struct to get input that will be stored in a string variable? I thought simply passing pz->szCompany to getline() would behave the same as if I had used the . operator on a normal instance of Pizza (instead of a pointer-to), but when I run this program it skips over the company name prompt completely.
// Part...
#include "stdio.h"
#include "string.h"
int main()
{
char *p;
p="hello world";
printf("p is %s \n",p);
return 0;
}
OUTPUT (on Intel PC): p is hello world
#include "stdio.h"
#include "string.h"
int main()
{
char *p;
strcpy(p,"hello");
printf("p is %s \n",p);
return 0;
}
OUTPUT (on Intel PC): Segmentation fault (core dumped)
...
Code:
#include "stdio.h"
#include "string.h"
int main()
{
char *p = "abc";
printf("p is %s \n", p);
return 0;
}
Output:
p is abc
Code:
#include "stdio.h"
#include "string.h"
int main()
{
char *p = "abc";
strcpy(p, "def");
printf("p is %s \n",p);
return 0;
}
Output:
Segmentation fault (core dumped)
Could someon...