edited by
1,643 views
0 votes
0 votes

A possible output of the following program fragment

#include <stdio.h>
int main(void) {
	static char were[ ] [5]={"harmot","merli","axari"};
	printf("%d %d %d",were,were[0],&were[0][0]); 
	return 0;
}

is

A) 262164 262164 262164

B) 262164 262165 262166

C) 262164 262164 262165

edited by

1 Answer

Best answer
2 votes
2 votes

The storage is done as follows:

h a r m o
m e r l i
a x a r i

Let 262164 be the base address of the 2-D array.

So, first printf i.e. "were" prints the address of the array.

second printf i.e. "were[0]" prints the address of the first 1-D array i.e. address of "harmo".

third printf i.e. "&were[0][0]" prints the address of the first character of "harmo" i.e. address of "h".

In all the cases, 262164 is printed. Hence A.

selected by

Related questions

1 votes
1 votes
1 answer
3
Rohit Gupta 8 asked Nov 8, 2017
456 views
What does the following fragment of C- program print?char t[] = "PROGRAM1234"; char *r = t; printf ("%s", r + r[6]- r[3]);Explain.
0 votes
0 votes
1 answer
4
Rohit Gupta 8 asked Nov 8, 2017
7,041 views
Let A be a square matrix of size n x n. Consider the following program. What is the expected output?C = 100 for(i=0; i<n; i++) for (j=0; j<n; j++) { Temp = A[i][j] + C A[...