74.1k views
2 votes
When a variable is stored in memory, it is associated with an address. To obtain the address of a variable, the & operator can be used. For example, &a gets the memory address of variable a. Let's try some examples. Write a C program addressOfScalar.c by inserting the code below in the main function

User Jorn
by
4.9k points

1 Answer

1 vote

Solution :

#include<stdio.h>

int main()

{

char charvar='\0';

printf("address of charvar = %p\\",(void*)(&charvar));

printf("address of charvar -1 = %p\\",(void*)(&charvar-1));

printf("address of charvar +1 = %p\\",(void*)(&charvar+1));

int intvar=1;

printf("address of intvar = %p\\",(void*)(&intvar));

printf("address of intvar -1 = %p\\",(void*)(&intvar-1));

printf("address of intvar +1 = %p\\",(void*)(&intvar+1));

}

User Milan Pithadia
by
5.2k points