retagged by
1,240 views
1 votes
1 votes
char *x[5] = {"abc","def","ghi","jkl","mno"};
char *y[5] = {"123","456","789","101","102"};
struct hcode {
	char *word;
}hcodes[5];
struct key {
	int id;
	char *word;
	struct hcode *password;
}keytab[5];
main () { 
	for(int i = 0 ; i < 5 ; i++) {
		keytab[i].word = y[i];
		keytab[i].id = i+1;
		keytab[i].password = hcodes+i;
		keytab[i].password->word = x[i];
	}
	
	struct key * ptr = keytab;
	
	ptr++->password++->word++;
	printf("%s,",++ptr++->word);
	printf("%s,",++ptr++->password++->word);
	printf("%s,",++ptr++->word);
	printf("%s\n",++ptr[0].password++->word);
	return 0;
}

$A.$ 456,hi,01,no

$B.$ 456,ghi,101,mno

$C.$ 56,hi,01,no

$D.$ 456,ef,01,no

retagged by

2 Answers

Best answer
6 votes
6 votes
char *x[5] = {"abc","def","ghi","jkl","mno"};
char *y[5] = {"123","456","789","101","102"};

struct hcode {
	char *word;
}hcodes[5];

struct key {
	int id;
	char *word;
	struct hcode *password;
}keytab[5];

int main () { 
	for(int i = 0 ; i < 5 ; i++) {
		keytab[i].word = y[i];
		keytab[i].id = i+1;
		keytab[i].password = hcodes+i; //same as &hcodes[i];
		keytab[i].password->word = x[i];
	}
//word is coming from x array and password word from y array
	struct key * ptr = keytab;//ptr points to keytab[0]
	
	ptr++->password++->word++; //password word of keytab[0] incremented - 
	//123 now becomes 23, password of keytab[0] becomes 456, 
	//ptr now points to keytab[1]
	
	printf("%s,",++ptr++->word); //ptr-> word is incremented and printed
//As per precedence rule, we get ++((ptr++)->word) and though ptr++ happens first, due to post increment, the effect will be visible only on the next use of ptr. 
	//which is 56. ptr is incremented to point to keytab[2]
	printf("%s,",++ptr++->password++->word); //ptr->password->word is incremented
	//and printed which is hi. ptr is incremented to point to keytab[3]
	printf("%s,",++ptr++->word); //as before this prints 01. ptr points to keytab[4]
	printf("%s\n",++ptr[0].password++->word); //ptr[0] = *(ptr); so, no is printed
	return 0;
}
selected by
0 votes
0 votes

Option no C. I've executed it in turboc++ 16 bit version. But d answer shud vary accordingly from compiler to compiler. 

Related questions

0 votes
0 votes
1 answer
1
Psnjit asked Jan 12, 2019
1,137 views
main(){unsigned int i= 255;char *p= &i;int j= *p;printf("%d\n", j);unsigned int k= *p;printf("%d", k);} Both the outputs are -1. I have even tried with - int i = 255(3rd ...
0 votes
0 votes
1 answer
2
Mr khan 3 asked Nov 3, 2018
978 views
#include<stdio.h void fun(int *p,int *q) { p=q; *p=q; } int i=0,j=1; int main() { fun(&i,&j); printf("%d%d",i,j); }What will be the output of i and j in 16-bit C Compiler...
0 votes
0 votes
0 answers
4
garvit_vijai asked Sep 2, 2018
683 views
Please explain the output for the following program: #include<stdio.h>int main() { int i = 100; int *a = &i; float *f = (float *)a; (*f)++; pri...