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);

}



main( ) { void *vp; char ch = ‘g’, *cp = “goofy”; int..

Answer / susie

Answer :

g20fy

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’.

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More C Code Interview Questions

program to Reverse a linked list

12 Answers   Aricent, Microsoft, Ness Technologies,


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

1 Answers  


write a c program to Create employee record by taking details like name, employee id, address and phone number. While taking the phone number, take either landline or mobile number. Ensure that the phone numbers of the employee are unique. Also display all the details

2 Answers   TCS,


main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit >> (i - (i -1))); } } a. 512, 256, 0, 0, 0 b. 256, 256, 0, 0, 0 c. 512, 512, 512, 512, 512 d. 256, 256, 256, 256, 256

2 Answers   HCL,


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

0 Answers   Honeywell,






main() { int i=5,j=10; i=i&=j&&10; printf("%d %d",i,j); }

1 Answers  


int a = 10 + 10 .... ,... A = A * A What would be the value of A? The answer is 120!! Could anyone explain this to me.

2 Answers   Bosch, eInfochips, HCL, IHCL,


program to find the roots of a quadratic equation

14 Answers   College School Exams Tests, Engineering, HP, IIIT, Infosys, Rajiv Gandhi University of Knowledge Technologies RGUKT, SSC,


main() { int c=- -2; printf("c=%d",c); }

1 Answers   TCS,


How to reverse a String without using C functions ?

33 Answers   Matrix, TCS, Wipro,


main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }

1 Answers   Zoho,


create a login program that ask username and password. if you input username or password 3 times wrong, the program will terminate else the program will prompt a message "congratulations"

2 Answers  


Categories