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
Hey! Want to work with us? Our youtube channel See our Jd Want to apply? Do it today

Use Me  ?

New searches
GATE-Computer-Science-Engineering-2017-->View question


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

#include
#include

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


By:satyashiromani

Taged users:
|satyashiromani|Oshal-Borkar|vaishnavi-Deshpande|milanyoyoyogmailcom|Umang|ThreeRed|Msshikhil|batsam22|deepuckraj|Manisha12|sumesh|Naveen-Kumar|Mansa|aksingh1818|milan-ransingh|Aparna-Dasgupta|leo|Aaditi|madachod|tichaona-garaidenga|ronald|tarun101|jinsnjjose|dillu550|bhagyaRaj|Vinit|thegdx|Abdul-Wajid|metaphor|bino

Likes:
Be first to like this question

Dislikes:
Be first to dislike this question

Talk about thisDelete|Like|Dislike|


Answers

B) 3

Explanation: 
((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


deepuckraj

Likes:
Be first to like this answer

Dislikes:
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!