Q55 Consider the following C program gate computer science 2017

The Eduladder is a community of students, teachers, and programmers just interested to make you pass any exams. So we solve previous year question papers for you.
See Our team
Wondering how we keep quality?
Got unsolved questions?

Ask Questions
GATE-Computer-Science-Engineering-2017-->View question

Q.55) Consider the following C program. -gate computer science 2017


void printlength (char *s, char *t)
  unsigned int c = 0;
  int len = ((strlen (s) - strlen (t)) > c) ? strlen (s) : strlen (t);
  printf("%d\n", len);

void main()
  char *x = "abc";
  char *y = "defgh";
  printlength(x, y);
Recall that strlen is defined in string.h as returning a value of type size_t, which is an unsigned int . The output of the program is _________. Note: This questions appeared as Numerical Answer Type.
A) 2
B) 3
C) 4
D) 5


Taged users:

Be first to like this question

Be first to dislike this question

Talk about thisDelete|Like|Dislike|


B) 3

((strlen(s) - strlen(t)) > c) ? strlen (s) : strlen (t) = (3 - 5 > 0) = (-2 > 0) Important point here is while comparing -2 with c,  result will be a positive number as c is unsigned. So, out of these two , strlen (s) will be printed. Therefore, option B is correct. See the code for clarification :http://code.geeksforgeeks.org/hDPNVE

This explanation is contributed by Deepak Raj


Be first to like this answer

Be first to dislike this answer
Talk about this|Once you have earned teacher badge you can edit this questionDelete|Like|Dislike|

Can you help us to add better answer here? Please see this

Not the answer you're looking for? Browse other questions from this Question paper or ask your own question.

Join eduladder!