troubleshooting Question

each pointer declaration starts with a new random address so (p+1)-1!=p

Avatar of rgb192
rgb192Flag for United States of America asked on
C
12 Comments1 Solution741 ViewsLast Modified:
pointers are not in numerical order
in theory:
int *p=A
print P //200
print P+1=204
print P+2=208

//Character arrays and pointers
#include<stdio.h>
#include<string.h>
void printOnScreen(const char* C)
{
	int j = 0;
	char theDisplay;
	//C[0] = 'A';
	while (*C !='\0') //C[j]=*(C+j)
	{
		theDisplay = *C;
		printf("%c", *C);
		C++;
	}
	printf("\n");
}

int main()
{
	int A[] = { 1, 2, 3, 4, 5 };
	char C[10] = "Hello";
	char value = *(C);
	char value1 = *(C + 1);
	char value2 = *(C + 2);
	char value3 = *(C + 3);
	int address = &C;
	int address1 = &C + 1;
	int address2 = &C + 2;
	int address3 = &C + 3;
	int *p = C;
	int *p2 = C + 2;
	int *p2Again = p + 2;
	printOnScreen(C);
	//printOnScreen(value);
	int j;
	int varC;
	for (j = 0; j < 5; j++){
		varC=C[j];
	}

}

in visual studios:
each address starts randomly
(see locals)
am I missing something?

pointers are not in numerical order.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros