|
INTERVIEW QUESTIONS
MAINFRAME
JCL
DETAILS
Question: 51) 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); }
Answer: 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.
|
|
|
Category |
JCL Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 7617 users |
Added on |
9/2/2014 |
Views |
69585 |
Rate it! |
|
|
Question:
51) 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); }
Answer:
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.
Source: CoolInterview.com
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
50) main( ) { char *q; int j; for (j=0; j<3; j++) scanf(%s ,(q+j)); for (j=0; j<3; j++) printf(%c ,*(q+j)); for (j=0; j<3; j++) printf(%s ,(q+j)); }
|
View Answer
|
|
49) main( ) { static int a[ ] = {0,1,2,3,4}; int *p[ ] = {a,a+1,a+2,a+3,a+4}; int **ptr = p; ptr++; printf(
%d %d %d, ptr-p, *ptr-a, **ptr); *ptr++; printf(
%d %d %d, ptr-p, *ptr-a, **ptr); *++ptr; printf(
%d %d %d, ptr-p, *ptr-a, **ptr); ++*ptr; printf(
%d %d %d, ptr-p, *ptr-a, **ptr); }
|
View Answer
|
|
48) main( ) { int a[ ] = {10,20,30,40,50},j,*p; for(j=0; j<5; j++) { printf(%d ,*a); a++; } p = a; for(j=0; j<5; j++) { printf(%d ,*p); p++; } }
|
View Answer
|
|
47) main( ) { int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}}; printf(%u %u %u %d
,a,*a,**a,***a); printf(%u %u %u %d
,a+1,*a+1,**a+1,***a+1); }
|
View Answer
|
|
46) main() { show(); } void show() { printf("I'm the greatest"); }
|
} - JCL Interview Questions & Answers">
View Answer
|
|
45) main() { extern out; printf("%d", out); } int out=100;
|
} int out=100; - JCL Interview Questions & Answers">
View Answer
|
|
44) main() { printf("%d", out); } int out=100;
|
} int out=100; - JCL Interview Questions & Answers">
View Answer
|
|
43) main() { extern int i; i=20; printf("%d",sizeof(i)); }
|
} - JCL Interview Questions & Answers">
View Answer
|
|
42) #include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }
|
View Answer
|
|
41) #include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }
|
View Answer
|
|
40) #include<stdio.h> main() { char s[]={'a','b','c','
','c','
|
View Answer
|
|
39) main() { int i=0; for(;i++;printf("%d",i)) ; printf("%d",i); }
|
printf("%d",i); } - JCL Interview Questions & Answers">
View Answer
|
|
38) #define f(g,g2) g##g2 main() { int var12=100; printf("%d",f(var,12)); }
|
} - JCL Interview Questions & Answers">
View Answer
|
|
37) main() { int i; printf("%d",scanf("%d",&i)); // value 10 is given as input here }
|
}
View Answer
|
|
36) #include<stdio.h> main() { int i=1,j=2; switch(i) { case 1: printf("GOOD"); break; case j: printf("BAD"); break; } }
|
View Answer
|
|
35) void main() { int i=5; printf("%d",i+++++i); }
|
} - JCL Interview Questions & Answers">
View Answer
|
|
34) void main() { int i=5; printf("%d",i++ + ++i); }
|
} - JCL Interview Questions & Answers">
View Answer
|
|
33) main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); }
|
- JCL Interview Questions & Answers">
View Answer
|
|
32) main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }
|
- JCL Interview Questions & Answers">
View Answer
|
|
31) main() { char *p; p="Hello"; printf("%c
",*&*p); }
|
printf("%c
",*&*p); } - JCL Interview Questions & Answers">
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All JCL Interview Questions & Answers - Exam Mode /
Learning Mode
|