Note 1

Take Note:

Take a note while surfing.





Note With Ink

Give your Note a Colorful Tag.




Easy to Access

Stay on same information and in Sync wherever you are.

Note 2

Take Note:

Organize your information,It may take Shape.





Think With Ink

Differ your Content by Color.




Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3

Take Note:

Don't Let information to miss,Because it take shape





Note With Ink

Simple an Easy Way to take a note.




Easy to Access

Get the same in next visit.

C Programming :: Pointers

Home > C Programming > Pointers > General Questions

1. What is the output of the following C Program?

#include
void main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

++ operator when applied to pointers increments address according to their corresponding data-types.

Workspace

Tags:

No Tags on this question yet!

2. What is the output of the following C Program?

#include
void main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

Workspace

Tags:

No Tags on this question yet!

3. What is the output of the following C Program?

#include
void main()
{
char far *farther,*farthest;

printf("%d %d",sizeof(farther),sizeof(farthest));
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option E

Explanation:

the second pointer is of char type and not a far pointer

Workspace

Tags:

No Tags on this question yet!

4. What is the output of the following C Program?

#include
void main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

The variable i is a block level variable and the visibility is inside that block only. But the lifetime of i is lifetime of the function so it lives upto the exit of main function. Since the i is still allocated space, *j prints the value stored in i since j points i.

Workspace

Tags:

No Tags on this question yet!

5. What is the output of the following C Program?

#include
int main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option C

Explanation:

* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again
& references it to an address and * dereferences it to the value H.

Workspace

Tags:

No Tags on this question yet!

6. What is the output of the following C Program?

#include
int main()
{
char *cptr,c; void *vptr,v; c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option A

Explanation:

You can create a variable of type void * but not of type void, since void is an empty type. In the second line you are creating variable vptr of type void * and v of type void hence an error.

Workspace

Tags:

No Tags on this question yet!

7. What is the output of the following C Program?

#include
int one_d[]={1,2,3};
int main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

Tags:

No Tags on this question yet!

8. What is the output of the following C Program?

#include
int main( ){
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf("%u %u %u %d \n",a,*a,**a,***a);
printf("%u %u %u %d \n",a+1,*a+1,**a+1,***a+1);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option D

Explanation:

The given array is a 3-D one. It can also be viewed as a 1-D array.
2 4 7 8 3 4 2 2 2 3 3 4
1000 1002 1004 1006 1008 1010 1012 1014 1016 1018 1020 1022
thus, for the first printf statement a, *a, **a give address of first element .
since the indirection ***a gives the value. Hence, the first line of the output.
The second printf a+1 increases in the third dimension thus points to value at 114, *a+1 increments in second dimension thus points to 104, **a +1 increments the first dimension thus points to 102 and ***a+1 first gets the value at first location and then increments it by 1.

Workspace

Tags:

No Tags on this question yet!

9. What is the output of the following C Program?

#include
int main(){
void *vp;
char ch = 'g', *cp = "goofy";
int j '= 20;
vp = &ch;
printf("%c", *(char *)vp);
vp = &j;
printf("%d",*(int *)vp);
vp = cp;
printf("%s",(char *)vp + 3);
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

Since a void pointer is used it can be type casted to any other type pointer. vp = &ch stores address of char ch and the next statement prints the value stored in vp after type casting it to the proper data type pointer. the output is "g".
Similarly the output from second printf is "20". The third printf statement type casts it to print the string from the 4th value hence the output is "fy".

Workspace

Tags:

No Tags on this question yet!

10. What is the output of the following 'C' program ?

#include
int main()
{
char *p;
p="%d\n";
p++; p++;
printf(p-2,300);
return 0;
}

View Answer | Discuss in Forum | Workspace | Asked In |

Answer: Option B

Explanation:

The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.

Workspace

Tags:

No Tags on this question yet!