|
INTERVIEW QUESTIONS
MAINFRAME
JCL
DETAILS
Question: 52) main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }
Answer: Answer: ck Explanation: In this problem we have an array of char pointers pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p hold the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1 – 1 = s . the indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is ‘ck’.
|
|
|
Category |
JCL Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.2) By 7358 users |
Added on |
9/2/2014 |
Views |
68421 |
Rate it! |
|
|
Question:
52) main ( ) { static char *s[ ] = {“black”, “white”, “yellow”, “violet”}; char **ptr[ ] = {s+3, s+2, s+1, s}, ***p; p = ptr; **++p; printf(“%s”,*--*++p + 3); }
Answer:
Answer: ck Explanation: In this problem we have an array of char pointers pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p hold the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated *++p causes gets value s+1 then the pre decrement is executed and we get s+1 – 1 = s . the indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is ‘ck’.
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 |
|
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); }
|
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
|
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
|