C Expressions and Control Flow questions

Q11

GATE CS 2015 CS-3C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program segment.
#include <stdio.h>

int main()
{
    char s1[7] = "1234", *p;
    p = s1 + 2;
    *p = '0';
    printf("%s", s1);
}
What will be printed by the program?
Show answer without attempting

Answer: C

Q42

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program.
#include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;

int main ( )
{
    int x = 1;
    x += f1() + f2() + f3() + f2();
    printf("%d", x);
    return 0;
}

int f1() { int x = 25; x++; return x;}
int f2() { static int x = 50; x++; return x;}
int f3() { x *= 10; return x;}
The output of the program is ____________.
Show answer without attempting

Answer: 230

Q53

GATE CS 2015 CS-3C ProgrammingNAT2 marks
Consider the following C program:
#include<stdio.h>
int main( )
{
    int i, j, k = 0;
    j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
    k -= --j;
    for(i = 0; i < 5; i++)
    {
        switch(i + k)
        {
            case 1:
            case 2: printf("\n%d", i+k);
            case 3: printf("\n%d", i+k);
            default: printf("\n%d", i+k);
        }
    }
    return 0;
}
The number of times printf statement is executed is ____________.
Show answer without attempting

Answer: 10

Q65

GATE CS 2015 CS-1C ProgrammingMCQ2 marks−2/3 if wrong
Consider the following pseudo code, where xx and yy are positive integers.
begin
  q := 0
  r := x
  while r >= y do
    begin
      r := r - y
      q := q + 1
    end
end
The post condition that needs to be satisfied after the program terminates is
Show answer without attempting

Answer: B

0/40 correct0 marks

Related topics in C Programming