Test6 Answers
- What will be the output of the following nested if-else statement?
#include<stdio.h>
void main(){
int x=0;
If(x++){
printf("TRUE");
}
else if(x == 1){
printf("FALSE");
}
}
ANS: Compile time error
EXPLANATION: In line-4 'if' is a keyword which is always in lower cases.
- Select the correct output for the below C code?
#include <stdio.h>
static int i = 10;
int main() {
i = 5;
for(i = 0; i < 5; i++) {
static int a = 10;
printf("%d ", a++);
}
return 0;
}
ANS: 10 11 12 13 14
EXPLANATION: A static int variable remains in memory while the program is running.
In first iteration,
i=0, 0<5 condition is true inside the loop variable a is declared as static int and initialized with value 10. Now print value of a(10) and then increment a value(11).
In second iteration,
i=1, 1<5 condition true, a never initialized again because of static, print value of a(11) and then increment a value(12),...,so on.
- What is the output of the code given below?
#include<stdio.h>
void main() {
int i = 0;
do {
i++ = ++i;
printf("Hello CodeMarathon");
} while (i < 0);
}
ANS: Compile time error
EXPLANATION: We can not use increment left-side of assignment operator.
- Select the correct output for the below C code?
#include <stdio.h>
char* myfunc(char *ptr) {
ptr += 4;
return(ptr);
}
void main() {
char *x, *y;
x = "CodeMarathon";
y = myfunc(x);
printf("%s", y);
}
ANS: Marathon
EXPLANATION:
- What is the output of the code given below?
#include <stdio.h>
void main() {
int b = 15, c = 5, d = 8, e = 8, result;
result = b > c ? c > d ? 12 : d > e ? 13 : 14 : 15;
printf("%d\n", result);
}
ANS:
EXPLANATION:
- What will be the output of the following C code?
#include <stdio.h>
int i = 40;
extern int i;
int main() {
do{
printf("%d", i++);
}while (5,4,3,2,1,0);
return 0;
}
ANS:
EXPLANATION:
- Select the correct output for the below C code?
#include <stdio.h>
struct point {
int x;
int y;
} p[] = {1, 2, 3, 4, 5};
void display(struct point p[]) {
printf("%d %d\n", p->x, p[2].y);
}
void main() {
display(p);
}
ANS:
EXPLANATION:
- What is the output of the code given below?
#include <stdio.h>
void main() {
int x = 10;
printf("%d %d %d\n", x <= 10, x == 40, x >= 10);
}
ANS:
EXPLANATION:
- What will be the output of the below C code.
main() {
char ptr[] = "CQuestions";
printf("%d", -3[ptr]);
}
ANS:
EXPLANATION:
- What is the output of the code given below?
#include <stdio.h>
void main() {
int a = 10, b = 20, c = 30;
(c > b > a) ? printf("TRUE") : printf("FALSE");
}
ANS:
EXPLANATION: