GATE Solved Paper 2017-19 - GATE 2017 Shift 1

36. Consider the following C program.
#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

  • Option : C
  • 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 c is correct
Cancel reply
Cancel reply

37. Consider the following languages over the alphabet ∑= {a,b,c}. Let L1 = {an bncm | m, n >= 0 } and L2 = {ambncn| m, n >= 0}.
Which of the following are context-free languages ?
I. L1 ∪ L2 
II. L1 ∩ L2

  • Option : A
  • Explanation :
    Union of context free language is also context free language.
    L1 = { an bn cm| m >= 0 and n >= 0 } and
    L2 = { am bncn| n >= 0 and m >= 0 }
    L3 = L1 ∪ L2 = { anbncm∪ ambncn| n >= 0, m >= 0 } is also context free.
    L1 says number of a’s should be equal to number of b’s and L2 says number of b’s should be equal to number of c’s. Their union says either of two conditions to be true. So it is also context free language.
    Intersection of CFG may or may not be CFG.
    L3 = L1 ∩ L2 = { anbncn| n >= 0 } need not be context free
Cancel reply
Cancel reply