Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing

# C Programming - Strings - Discussion

@ : Home > C Programming > Strings > Find Output of Program - Discussion

"No one is as deaf as the man who will not listen."
- (Proverb)
18.

What will be the output of the program ?

``````#include<stdio.h>

int main()
{
static char mess[6][30] = {"Don't walk in front of me...",
"I may not follow;",
"Don't walk behind me...",
"Just walk beside me...",
"And be my friend." };

printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));
return 0;
}
``````

 [A]. t, t [B]. k, k [C]. n, k [D]. m, f

Explanation:

No answer description available for this question.

 Swetha said: (Mon, Nov 8, 2010 03:48:03 AM) Please give us more details of solving this type of questions

 Abhimanyu Verma said: (Sat, Nov 13, 2010 12:41:43 AM) As we can see this is a matrix having 6+1 row and 30+1 column. So now *(mess[2]+9)means that third row of matrix that is "Don't walk behind me...", and its (9+1)th character that is K and *(*(mess+2)+9)) this one have the same meaning as *(mess[2]+9)bcoz a[i]=*(a+i). So has same value K.....

 Tim said: (Thu, Dec 2, 2010 02:57:18 PM) Yes, the problem is about PRECEDENCE of the * operator vs pointer arithmetic. The expression * (mess+2) +9 is evaluated as mess+2 first (because it is within parentheses) which evaluates to the THIRD ROW of the matrix "mess". This is a char* value, so the next operation is to add +9 to that char* -- which gives us a pointer to the character 'k'. If you change the +9 to +j and do a printf for one character at a time, j = 0 to 9, then you will see you are printing the first 10 characters of the second row of the variable 'mess'.

 Raghu said: (Wed, Jun 29, 2011 06:54:21 AM) *(mess[2]+9)=mess[2] is incremented in the position for 9 times and k is printed. *(*(mess+2)+9)= *(mess+2)=*mess[2]

 Sonu said: (Thu, Jul 28, 2011 01:08:40 PM) Thanks Abhimanyu.

 Sss said: (Sat, Nov 12, 2011 05:36:57 PM) Thanks Abhimanyu.

 Inside C said: (Sun, Jan 27, 2013 12:44:44 PM) *(mess[2]+9) =>mess[2][9] *(*(mess+2)+9)) =>*(mess[2]+9) =>mess[2][9] So simple logic is * and + combines to form [].

 Raju Singh Kumai said: (Wed, Mar 13, 2013 04:40:37 PM) *(mess[2]+9) can be written as mess[2][9] which implies 3 line 10 char.(in c we start from 0) which is 'k', *(*(mess+2)+9))=*(mess[2]+9) = mess[2][9] = k. So the output will be k, k.