Q1. Find the o/p:
main() {
char *p;
p="Hello";
printf("%c\n",*&*p);
}
Ans:
H
Q2. Find the o/p:
main() {
int i=1;
while (i<=5){ printf("%d",i); if (i>2)
i++;
}
}
fun() {
here:
printf("PP");
}
Ans:
Compiler error: Undefined label 'here' in function main
Q3. Find the o/p:
void main() {
int i=5;
printf("%d",i++ + ++i);
}
Ans:
Output Cannot be predicted exactly.
Explanation:
Side effects are involved in the evaluation of i.
Explanation:
Side effects are involved in the evaluation of i.
Q4. Find the o/p:
main() {
int i=1,j=2;
switch(i) {
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
Ans:
Compiler Error: Constant expression required in function main.
Explanation:
The case statement can have only constant expressions (this implies that
we cannot use variable names directly so an error).
Note:
Enumerated types can be used in case statements.
Explanation:
The case statement can have only constant expressions (this implies that
we cannot use variable names directly so an error).
Note:
Enumerated types can be used in case statements.
Q5. Find the o/p:
main() {
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
Ans:
1
Explanation:
Scanf returns number of items successfully read.Here 10 is given as input
which should have been scanned successfully. So number of items read is 1.
Q6. Find the o/p:
#define f(g,g2) g##g2
main() {
int var12=100;
printf("%d",f(var,12));
}
Ans:
100
Q7. Find the o/p:
main() {
int i=0;
for(;i++;printf("%d",i)) ;
}
Ans:
1
Q8. Find the o/p:
# include < stdio.h >
main() {
printf("%d", out);
}
int out=100;
Ans:
Compiler error: undefined symbol out in function main.
Explanation:
The rule is that a variable is available for use from the point of declaration.
Even though a is a global variable, it is not available for main. Hence an error.
Explanation:
The rule is that a variable is available for use from the point of declaration.
Even though a is a global variable, it is not available for main. Hence an error.
Q9. Find the o/p:
#include <stdio.h>
main() {
extern out;
printf("%d", out);
}
int out=100;
Ans:
100
Explanation:
This is the correct way of writing the previous program.
Explanation:
This is the correct way of writing the previous program.
Q10. Find the o/p of this:
main( ) {
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++){ printf(“%d” ,*; a++; } p = a; for(j=0; j<5; j++){ printf(“%d ” ,*p); p++; } }
Ans:
Compiler error: lvalue required.
Explanation:
Error is in line with statement a++. The operand must be an lvalue and may be of any of
scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue.
Q11. Find the o/p:
main() {
static char *s[ ] = {“black”, “white”, “yellow”, “violet”};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(“%s”,*--*++p + 3);
}
Ans:
ck
Q12. Find the o/p:
main() {
int i,j;
for(i=0;i<=10;i++){ j+=5; assert(i<5); }
Runtime error: Abnormal program termination.
Explaination:
assert failed (i<5),,
asserts are used during debugging to make sure that certain conditions are
satisfied. If assertion fails, the program will terminate reporting the same. After
debugging use,
#undef NDEBUG
and this will disable all the assertions from the source code. Assertion is a
good debugging tool to make use of.
Explaination:
assert failed (i<5),
asserts are used during debugging to make sure that certain conditions are
satisfied. If assertion fails, the program will terminate reporting the same. After
debugging use,
#undef NDEBUG
and this will disable all the assertions from the source code. Assertion is a
good debugging tool to make use of.
Q13.What are the files which are automatically opened when a C file is executed?
Ans:
stdin, stdout, stderr (standard input,standard output,standard error).
No comments:
Post a Comment