1. What will be the output of following program?
C
Options:
(a)equal
(b)greater than
(c)less than
(d)compiler error
(e)none of the above
C
Options:
(a)i am good
(b)i
(c)good
(d)iamgood
(e)Compiler error
C
Options:
(a)7 7
(b)8 8
(c)8 7
(d)7 8
(e)None of the above
C
Options:
(a)Aqua
(b)AquaGreenOther
(c)AquaGreen
(d)Red
(e)none of the above
C
#include<stdio.h>
void main()
{
int i = 10;
static int x = i;
if (x == i)
printf("equal");
else if (x < i)))
printf("less than");
else
printf("greater than");
}
Answer: (d)Compiler errorExplanation: Here 'x' is a static variable and 'i' is an auto variable. Auto variables are run time entities, compared to static, which are load time entities. Run time variables cannot be initialized with load time variables. 2. What will be the output of following program?
#include<stdio.h>
void main()
{
printf("%s", "i"
"am"
"good");
}
Answer: (d)iamgoodExplanation: In C, string constant "ab" is same as "a" "b". 3. What will be the output of following program?
#include<stdio.h>
#include <string.h>
void main()
{
printf("%d %d", sizeof("program"), strlen("program"));
}
Answer: (c)8 7Explanation: strlen returns length of string without counting the null character, whereas sizeof also includes the null character when counting size of string. 4. What will be the output of following program?
#include<stdio.h>
void main()
{
int colour = 2;
switch (colour) {
case 0:
printf("Black");
case 1:
printf("Red");
case 2:
printf("Aqua");
case 3:
printf("Green");
default:
printf("Other");
}
}
Answer: (b)AquaGreenOtherExplanation: There are no break statements in switch case, so all statements after case 2, including the default statement, will be executed. 5. What will be the output of following program?
#include<stdio.h>
void main()
{
if (printf("cisgood"))
printf("i know c");
else
printf("i know c++");
}
Options:
(a)i know c
(b)i know c++
(c)cisgoodi know c
(d)cisgoodi know c++
(e)compiler error
Answer: (c)cisgoodi know cExplanation: The return type of printf is integer, that is the number of characters including blank spaces. So, here in if condition, printf evaluates to 7, which is non-negative. Thus follows the true condition.