123k views
5 votes
Define the following variables (in a new file and a new main() function):

• Integer value a and b
• Pointer variable p and q (pointers to integer values)
• Set the value of a to 5 and value of b to 7
• Set p to point to a and q to point to b (in other words assign the address of variables to pointers)

1 Answer

7 votes

Answer:

#include<stdio.h>

int main()//driver function

{

int a=5;//initializing variable a

int b=7;//initializing variable b

int *p,*q;//declaring pointers p and q

p=&a;//assigning the address of a to p

q=&b;//assigning the address of b to q

printf("value of a is %d\\",a);

printf("value of b is %d\\",b);

printf("value of pointer p is %d\\",*p);

printf("value of pointer q is %d\\",*q);

printf("address of a is %d\\",&a);

printf("address of b is %d\\",&b);

return 0;

}

Output

value of a is 5

value of b is 7

value of pointer p is 5

value of pointer q is 7

address of a is -783856608

address of b is -783856604

User Ashley Pillay
by
7.8k points