Professional Documents
Culture Documents
Shriram
K Vasudevan
Technical
Manager
10/7/16
Question..
1. What is the output of following program?
main()
{
int x = -10;
printf("%d\n", ~x+1);
}
Choices:
A)11
b)-8
c)10
Answer ?
2
10/7/16
Answer
-10 is stored as 8 4 2 1
1 0 1 0(+10)
0 1 0 1 (1s comp)
+ 1 will get 2s comp
--------------------------0 1 1 0 (-10)
Negation = 1 0 0 1 + 1 = 9 + 1 = 10.
10/7/16
Question..
2. What is the output of following program?
main()
{
printf("%c\n", '1' + 1);
}
Choices:
a)ASCII value of '1' is required to find out the answer
b)2
c)50
d)Syntax Error
4
10/7/16
Answer
10/7/16
Question..
3. What is output of following
program?
main()
{
int x = 1;
Choices:
int y = 2;
a)6
switch(x | y)
b)4
{
c)5
case 1: x = 2;
d)3
case 2: x = 3;
case 3: x = 4;
case 4: x = 5;
default:x = 6;
}
printf("%d\n", x);
}
10/7/16
Answer
a. There are no break statements so,
irrespective of the value of x, last case
(default) will be executed. This is an example
of fall-through situation.
10/7/16
Question..
4. What is the output of the following program?
main()
{
printf("%d\n", 100 / 10 / 10);
}
a)1
b)100
c)10
d)0
8
10/7/16
Answer
10/7/16
Question..
5.
main()
{
int a=5;
if (a=1)
{
printf("%d", a);
}
}
In the above code
10/7/16
Answer
11
10/7/16
Question..
6. int main()
{
int a[10];
int i;
for (i=0; i<10; i++)
a[i] = i;
printf("%d", a[-1]);
}
The above program
12
10/7/16
Answer
13
10/7/16
Question..
7. What is the output of the following program?
main()
{
int a=3, b=5, c=1;
int x=8;
x = a < (b < c);
printf("%d", x);
}
a)1
b)8
c)Will encounter run time error
d)0
14
10/7/16
Answer
15
10/7/16
Question..
8.
16
10/7/16
Question
9.
17
10/7/16
Question
10.
Declaration
18
10/7/16
Question
11.
19
10/7/16
Question
12.
20
10/7/16
Question
13.
21
10/7/16
Question
14.
22
10/7/16
Question
15.
23
10/7/16
Question
16.
Nope!! Am sorry!
24
10/7/16
Question
17.
OUTPUT??
D is the answer.. And the
output is 12345678910
25
10/7/16
Question
18
1. What is while (1) ???
2. What will be the output?
Answers:
1. Infinite loop
2. 12345678910
26
10/7/16
Question
19.
A is the
answer Boss!
27
10/7/16
Question
20,21 and 22
10/7/16
Question
24.
S!! Of
course .
. Case
j
AM I WRONG SOMEWHERE????
29
10/7/16
Question
25.
30
10/7/16
Question
26.
Anything wrong
here???????????????
Not at all, Switch is no harmful!
31
10/7/16
Question
27.
Ouput???
Sorry.. No output
32
10/7/16
Question
28.
Answer:
7. Printf wont
get run!!!
10/7/16
Question
29.
34
10/7/16
Question
30.
35
10/7/16
Question
30.
36
10/7/16
Question
31, 32.
#include <stdio.h>
main( )
{
int i=7;
printf ("\n %d %d",++i,++i);
getchar();
}
Answer:
Compiler will go mad! Order of
evaluation will not be clear and the
output can be 9 8
37
#include
<stdio.h>
main( )
{
int i=7;
printf ("\n %d",+
+i);
printf ("\n %d",+
+i);
getchar();
Now it would be
}
perfect!! 8,9
10/7/16
Question
33
#include <stdio.h>
main( )
{
int x=10, y=20, z=5,i;
i=x<y<z;
printf ("\n %d", i);
getchar();
}
Answer:
(10<20)<5
So answer is 1.
Options
1, 0
38
10/7/16
Question
34
What will this do ?
z = (a > b) ? a : b;
Answer:
Thus to set z to the maximum of a and b,
z = (a > b) ? a : b; /* assign z the maximum of a and
b */
39
10/7/16
Question
35
Answer:
3
0
1
Note:
! Is evaluated before && which is evaluated
before ||
40
10/7/16
Question
36
C.
Simple!!!
41
10/7/16
Question
37
Tell me
your
opinion?
42
10/7/16
Question
38
Type casting .. It is
A
43
10/7/16
Question
39
c. You cannot re
declare dude!
44
10/7/16
Question
40
45
10/7/16
Question
41, 42
Y
Till
overflow!
46
10/7/16
Question
43,44,45
47
NOPE.
10/7/16
Question
46, 47
Re arrange this #define in
such a way u will get 25
as output.
# define SQR (x)
((x)*(x))
Simple!!
3+(2*3)+2
3+6+2=11
48
10/7/16
Question
48
49
10/7/16
Question
50, 51
51
10/7/16
Question
52,53,54
52
10/7/16
Question
55
53
10/7/16
Question
56
54
10/7/16
Question
57
55
10/7/16
Question
58
#define MAKEDOUBLE(x) x+x
a = MAKEDOUBLE(4) * 3;
VALUE OF a?
a)24
b)16
c)8
d)None
10/7/16
Question
59
What is the output of the following program?
int x[100];
main()
{
printf("%d\n",x[99]);
}
a)Unpredicatable
b)Runtime error
c)0
d)99
57
10/7/16
Question
63
How many times is "Hello world" is printed in following program.
main()
{
unsigned int i = 5;
while (--i >= 0)
{
printf("Hello World\n");
}
}
a)5
b)6
c)Infinite
d)Program will not compile
The correct answer is c. Being an unsigned number, value of i cannot be less than 0.
So, the statement i >= 0 will be always true. Hence, this program goes into an
infinite loop.
61
10/7/16
Question
64
The preprocessor can trap simple errors like missing
declarations, nested comments or mismatch of braces
a)True
b)False
c)Depends on the compiler
d)None of the above
The correct answer is b. The only function of preprocessor is to expand macros. They can be thought of
as intelligent text processors. Only compilers have the
capability to perform syntax checking.
62
10/7/16
Question
65
What is the output of the following program.
main()
{
char str[7] = "Strings";
printf("%s", str);
}
a)Strings
b)Not predicatable
c)Compilation error
d)None of the above
The correct answer is b. "Strings" is internally stored as "Strings\0"
which needs 8 bytes of storage space. Since only 7 bytes are allocated
for the str, '\0' is written into some location in stack after 7 bytes and
this results in stack corruption. So, the behavior is not predictable.
63
10/7/16
Question
66
What is the output of following program?
main()
{
int y = 100;
const int x = y;
printf("%d\n", x);
}
a)100
b)Garbage value
c)Error
d)0
10/7/16
Question
67
In a C file, the following line is present:
#define FAST_COMPUTE
When trying to compile the program,
10/7/16
Question
68
In a C Program, stack is used for
10/7/16
Question
69
Memory leak in a program is mostly due to
10/7/16
Question
70
int main()
{
int i = 0;
int sizeint;
sizeint = sizeof i++;
printf("%d\n", i);
return 0;
}
Considering that integer requires 4 bytes of memory, the value of
i printed by the above program is:
a)1
b)4
c)0
d)The above program encounters a compilation error.
The correct answer is c. sizeof is an operator. Once the sizeof the type int is determined, the expression is
not evaluated any further since sizeof(i++) and sizeof(i) both are same as sizeof(int)
68
10/7/16
Question
71
int main()
{
int i = 0;
int sizeint;
sizeint = sizeof(i++);
printf("%d\n", sizeint);
return 0;
}
a)1
b)2
c)4
d)The output will be machine dependent
The correct answer is d. In the above program, i is of integer type. An integer
could occupy either 2 or 4 or more bytes depending on the architecture of
the machine.
69
10/7/16
Question
72
int main()
{
int j = 6;
int i;
i = 5, j++;
printf("%d\n", i);
return 0;
}
Which of the following statements are true about the code snippet given above
10/7/16
Question
73
int main()
{
int j=6;
int i;
i = (5, j);
printf("%d %d\n", i, j);
return 0;
}
The output from the above program is:
a)5 6
b)6 6
c)6 7
d)The output is machine dependent
The correct answer is b. (5, j) is first evaluated as (5, 6). When placed in
parenthesis (5,6) would return 6 which gets assigned to i.
71
10/7/16
Question
74
int main()
{
int j=6;
int i;
i = (5, j++);
printf("%d %d\n", i, j);
return 0;
}
The output from the above program is:
a)5 6
b)6 6
c)6 7
d)The output is machine dependent
The correct answer is c. (5, j++) is first evaluated as (5, 6). When placed in
parenthesis (5,6) would return 6 which gets assigned to i. Then j is incremented.
72
10/7/16
Question
70
What is the output of following program?
main()
{
int x = 0;
int y = 0;
if (x++ && ++y)
{ ++x; }
printf("%d %d\n",x, y);
}
a)0 0
b)1 0
c)2 0
d)2 1
The correct answer is b. x++ translates to 0 (and then x is incremented to 1). Since FALSE && (anything)
would become zero, the second part is not evaluated (short-circuited). And overall condition is false and
hence ++x is not executed.
73
10/7/16
Question
75
What is the output of following program?
main()
{
int x = 0;
int y = 0;
if (++x || ++y)
{
x++;
}
printf("%d %d\n",x, y);
}
a)1 1
b)1 0
c)2 1
d)2 0
74
10/7/16
Question
76
What is the output of following program?
main()
{
int x = 0;
int y = 0;
if (!(++x && ++y))
{
x++;
}
printf("%d %d\n",x, y);
}
a)1 1
b)1 0
c)2 1
d)2 0
Sorry,
the correct answer is a. ++x translates to 1. ++y also needs to be evaluated as we have && operator. ++y translates to 1. !(TRUE &&
TRUE) translates to FALSE. Since overall condition translates to FALSE, x++ is not executed.
75
10/7/16
Question
77
What is the output of following program?
main()
{
int x = 0;
int y = 0;
if (!(++x || ++y))
{
x++;
}
printf("%d %d\n",x, y);
}
a)1 0
b)1 1
c)2 1
d)2 0
The correct answer is a. ++x translates to 1. The second part need to be evaluated as (TRUE ||
anything) would be TRUE. Since there is an overall NOT, condition translates to FALSE, x++ is
not executed.
76
10/7/16
Question
78
What is the output of following program?
main()
{
int x = 10;
int y = 20;
if (x <= y == 1)
{
++x;
}
printf("%d\n", x);
}
a)11
b)10
c)Compiler Dependent
d)Syntax Error
Sorry, the correct answer is a. Precedence: <= followed by ==. The given expression is
equivalent to (x <= y) == 1.
77
10/7/16
Question
79
What is the output of following program?
main()
{
int x = 1;
int y = 0;
if (x | y++)
{
++y;
}
printf("%d %d\n", x, y);
}
a)Compiler Dependent
b)1 1
c)1 0
d)1 2
Sorry, the correct answer is d. The expression (x | y++) has bit-wise OR. i.e the expression would always be evaluated
fully. Therefore y would get incremented twice (unlike logical OR ||, where evaluation of expression may be done partially
based on partial result).
78
10/7/16
Question
80
What is the output of following program?
#define DOUBLE(x) x + x
main()
{
printf("%d\n", DOUBLE(10)*2);
}
a)20
b)30
c)40
d)Syntax error
10/7/16
Question
81
What is the output of following program?
#define SQUARE(x) (x * x)
main()
{
int x = 10;
int y = 5;
printf("%d\n", SQUARE(x +y));
}
a)225
b)45
c)65
d)Syntax error
10/7/16
Question
82
What is the output of following program?
#define ABC(x) DEF(x)
#define DEF(x) GHI(x)
#define GHI(x) printf x
main()
{
int x = 100;
ABC(("value of x is %d\n", x));
}
a)value of x is 100
b)Syntax error
c)Linker error
d)Runtime error
81
10/7/16
Question
83 just know
82
10/7/16
Question
84
Assuming the code below is stored in a file "a.c" and the command "gcc a.c" is used to compile
the file, what is the output of this program:
#ifdef DEBUG
#define DEBUG_PRINT(x) printf("debug :%s\n", (x));
#else
#define DEBUG_PRINT(x)
#endif
main()
{
int x;
#if 0
x=10;
#endif
printf("%d\n", x);
DEBUG_PRINT("Exiting main");
}
83
10/7/16
Question
85
What is the output of following program?
main()
{
char **p = 0;
printf("%d\n", ++p);
}
a)4
b)Syntax Error
c)Runtime Error
d)Unpredictable output
84
10/7/16
Question
86
What is the output of following program?
main()
{
int x, y;
int *p1 = &x;
int *p2 = &y;
printf("%d\n", p1-p2);
}
a)4
b)1
c)-4
d)Syntax or Runtime error
the correct answer is b. All the local variables are stored in stack. So, x, y, p1 and p2, all
these variables will be part of the stack. Since, stack follows "last in first out" principle, the
first local variable is pushed into the stack. i.e x is pushed first, followed by y, followed by p1
and p2. So, &p2 and &p1 would differ by 4 bytes. Since p1 is pushed earlier than p2, it will
have higher memory address than p2. However, subtracting two pointers of the same type,
will give the "number of elements" between them and hence output is 1.
85
10/7/16
Question
87
What is the output of the following program?
main()
{
int x = 10;
int *p = &x;
printf("%d %d %d\n", x, *(&x), **(&p));
}
a)Syntax Error
b)Runtime Error
c)10 10 10
d)Unpredictable output as addresss of x and p are not known.
answer is c. Value of x is 10. *&x is nothing but x. *(&p) is not but p. **(&p)
is not but *p. So output would be 10 10 10.
86
10/7/16
Question
88
What is the output of the following program:
main()
{
int i=15;
char *str;
strcpy(str, "Hello, World!");
printf("i=%d\n", i--);
}
a)15
b)14
c)The program does not compile
d)Program behaviour is unpredictable
the correct answer is d. str being a pointer has only 4-bytes allocated for it to
store an address. Copying a string into it will corrupt the stack
87
10/7/16
Question
89
What is the output of the following program:
#include <stdio.h>
int i=0;
main()
{
int i=5;
printf("%d\n", i++);
}
a)0
b)1
c)5
d)6
Correct answer is c. Though i is a global variable, the local value of i holds within
the block in which it is declared. So printf would print 5, and then a postincrement would take place.
88
10/7/16
Question
90
What is the output of the following program:
int i=5;
int f1(int i)
{
i=i/2;
return i;
}
main()
{
int i=10;
printf("%d, %d\n", f1(i), i);
}
a)5, 5
b)5, 10
c)10, 10
d)None of the above
Sorry, the correct answer is b. When f1() is called, the local copy of i which f1 receives as
argument(10) holds. The on-stack value of i is changed to 5 in f1 and 5 is returned from f1.
This is first printed in the printf statement when f1(i) is called, and then the on-stack variable i
which is assigned 10 is printed.
89
10/7/16
Question
91
What is wrong with the following program:
main()
{
char *s = "Hello World\n";
printf("%s", s);
}
a)s has memory for only 4-bytes so this will not compile.
b)Its behaviour is unpredictable since s has memory for only 4 bytes
c)Program will encounter segmentation violation
d)It will work without any problem
10/7/16
Question
92
A loader is
10/7/16
Question
93
What happens during "dynamic linking"?
10/7/16
Question
94
By overwriting into the stack area, which of the
following are you likely to corrupt:
10/7/16
Question
95
By overwriting memory in strings that are global
variables, which of the following are you likely to
corrupt?
a)Return address
b)Other global variables
c)local variables of calling functions
d)All of the above
10/7/16
Question
96
Which of the following statements is true
10/7/16
Question
97, 98, 99
NO
STDIO.H, STDLIB.H
10/7/16
Question
100 Century!!
What is a void ()
pointer?
int a = 5;
double b = 3.233;
void *vp; // void pointer
vp = &a;
printf ("\n a = %d", *((int *)vp));
vp = &b;
printf ("\n b = %f", *((double *)vp));
return 0;
}
O/P
shri@ubuntu:~$ ./file1
a=5
b = 3.233000
10/7/16
Question
101
Assuming that starting address is 1000, what would be the
output?
# include <stdio.h>
main ()
{
int array[] = {2,4,5,6,7};
printf ("%d %d", array,sizeof(array));
}
Answer:
1000, 20
(Note: 4 bytes for int in my compiler)
98
10/7/16
Question
102
Assuming that starting address is 1000, what
would be the output?
# include <stdio.h>
main ()
{
int arr[]={1,2,3,34,4};
printf ("%u %u", arr,&arr);
}
1000,1000
99
10/7/16
Question
103
Yes!!!
100
10/7/16
Question
104
What is the output of following code?
# include <stdio.h>
main ()
{
printf (10+"SACHIN TENDULKAR");
}
Output:
DULKAR
101
10/7/16
Question
105
# include <stdio.h>
main ()
{
printf ("%c","abcdefgh"[4]);
}
Answer:
102
10/7/16
Question
106
What is the output of following program?
main()
{
char x = 0x80;
int y = x;
printf("%d\n", y);
}
a)0
b)128
c)-128
d)Unpredictable
The correct answer is c. x is defined as a signed character. With 8 bits, data range
that can be represented is -128 to +127. So, 0x80 represents -128. When assigned
to an integer, -128 remains as is. Since the MSB is the sign bit, when value of
signed char is 0x80, sign bit is set. When this value is assigned to a signed integer,
the sign bit would get extended. Internally the value stored in y would be
0xFFFFFF80 which is the value of -128. Note that sign extension happens only for
signed data tyes. The value would show up as 128 if y was declared as unsigned.
103
10/7/16
Question
107
a)i
b)Program will have runtime error
c)Unpredictable
d)No visible output
the correct answer is d. To begin with p points to first character. Adding 9 to it,
makes it point to '0' since the string is terminated by a NULL value. So when 9 is
added to p which is a char pointer it points to an empty string and hence no
output will be printed on the screen.
104
10/7/16
Question
108
What is the output of following program?
main()
{
int y[2][2] = { {1,2}, {3,4} };
int *p = &y[1];
p = p + 1;
printf("%d\n",*p);
}
a)4
b)3
c)The program doesn't compile
d)Output is unpredicatable
the correct answer is a. Note that array indexing starts with 0. So, &y[1]
points to 3. After incrementing the integer pointer p by 1, it would point to
4.
105
10/7/16
Question
109
main()
{
printf("%d\n",f1(10,10));
}
Assuming f1 is defined in another file, which of the following statements are acceptable by
compiler as function prototype of f1.
1. extern int f1();
2. extern f1(int, int);
3. extern f1();
4. extern int f1(int, int);
a)All of them
b)4
c)3
d)1 & 4
the correct answer is a. To keep compiler happy, just an extern f1() is enough. However,
it is good practice to give complete prototype extern int f1(int, int).
the correct answer is a. To keep compiler happy, just an extern f1() is enough. However,
it is good practice to give complete prototype extern int f1(int, int).
106
10/7/16
Question
110
9)What is output of following program?
int y = 10;
main()
{
int x = 10;
int y = 20;
x = x + y;
if (x >= 30)
{
int y = 30;
x = x + y;
}
else
{
int y = 40;
x = x + y;
}
printf("%d\n", x);
}
a)40
b)50
c)60
d)70
Sorry, the correct answer is c.
107
10/7/16
Question
111
What is output of following program?
main()
{
int x = 10;
int y = 20;
if (x & y)
if(x | y) x = 20;
else x = 30;
printf("%d\n", x);
}
a)10
b)20
c)30
d)Unpredicatable
Sorry, the correct answer is a. Note that else belongs to second if. It is always a good
practice to put even single line blocks also within braces to avoid such confusion. Also,
appropriate indentation would enhance readability significantly giving lesser scope to
misinterpretation of code.
108
10/7/16
Question
113
What is the output of the following program?
int x[100];
main()
{
printf("%d\n",x[99]);
}
a)Unpredicatable
b)Runtime error
c)0
d)99
10/7/16
Question
114
How many times is "Hello world" is printed in following program.
main()
{
unsigned int i = 5;
while (--i >= 0)
{
printf("Hello World\n");
}
}
a)5
b)6
c)Infinite
d)Program will not compile
Sorry, the correct answer is c. Being an unsigned number, value of i cannot be less than 0.
So, the statement i >= 0 will be always true. Hence, this program goes into an infinite
loop. When i becomes 0 and decremented further, it wraps around and becomes MAXINT.
111
10/7/16
Question
116
What is the output of the following program:
#include <stdio.h>
int i=0;
main()
{
int i=5;
printf("%d\n", i++);
}
a)0
b)1
c)5
d)6
Sorry, the correct answer is c. Though i is a global variable, the local value of i holds
within the block in which it is declared. So printf would print 5, and then a postincrement would take place.
113
10/7/16
Question
117
What is the size of the following structure?
typedef struct
{
int ctrl1;
char flag;
int ctrl2;
char flag2;
int ctrl3;
} MYREG;
a)14
b)20
c)24
d)16
Sorry, the correct answer is b. There is a 3 byte padding added after flag and flag2 to
align the integers ctrl2 and ctrl3. Therefore size of this structure will be 20 bytes.
114
10/7/16
Question
118
What is the size of the following structure?
typedef struct
{
int ctrl1;
char flag;
char flag2;
int ctrl2;
int ctrl3;
} MYREG;
a)14
b)20
c)24
d)16
the correct answer is d. There is a 2-byte padding added before ctrl2 to align ctrl2
to a 4-byte boundary. Hence the size of this structure is 16.
115
10/7/16
Question
119
116
10/7/16
Question
120
10)
A loader is
10/7/16
Question
121
118
10/7/16
Question
122
Nothin
g
119
10/7/16
Q 123
void main(){
int const * p=5;
printf("%d",++(*p));
}
What is the answer?
Compiler error: Cannot modify a constant value.
120
10/7/16
Q 124
main(){
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
121
10/7/16
Answer
Answer:
I hate U
Explanation:
For floating point numbers (float, double, long
double) the values cannot be predicted
exactly. Depending on the number of bytes,
the precision with of the value represented
varies. Float takes 4 bytes and long double
takes 10 bytes. So float stores 0.9 with less
precision than long double.
Rule of Thumb:
Never compare or at-least be cautious when
122
Swim in the C.
using floatingLets
point
numbers with 10/7/16
relational
Q125
main() {
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
123
10/7/16
Answer
Answer:
54321
Explanation:
When static storage class is given, it is
initialized once. The change in the value of a
static variable is retained even between the
function calls. Main is also treated like any
other ordinary function, which can be called
recursively.
124
10/7/16
Q126
main(){
extern int i;
i=20;
printf("%d",i);
}
Answer:
Explanation:
specifies to the compiler that the memory for i is allocated in some other
program and that address will be given to the current program at the time
of linking. But linker finds that no other variable of name i is available in
any other program with memory space allocated for it. Hence a linker error
has occurred .
125
10/7/16
Q127
main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}
Answer:
00131
Explanation :
Logical operations always give a result of 1 or 0 . And also the logical AND (&&)
operator has higher priority over the logical OR (||) operator. So the expression i++
&& j++ && k++ is executed first. The result of this expression is 0 (-1 && -1 && 0
= 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always
gives 1 except for 0 || 0 combination- for which it gives 0). So the value of m is 1. The
values of other variables are also incremented by 1.
126
10/7/16
Q128
main(){
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}
Answer:
12
Explanation:
127
10/7/16
Q129
main(){
int i=3;
switch(i) {
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all other cases
doesn't match.
128
10/7/16
Q130
main(){
char string[]="Hello World";
display(string);
}
void display(char *string){
printf("%s",string);
}
Answer:
Compiler Error : Type mismatch in redeclaration of function display
Explanation :
In third line, when the function display is encountered, the compiler doesn't know
anything about the function display. It assumes the arguments and return types to be
integers, (which is the default type). When it sees the actual function display, the
arguments and type contradicts with what it has assumed previously. Hence a compile
time error occurs.
129
Lets Swim in the C.
10/7/16
q131
main(){
int c=- -2;
printf("c=%d",c);
}
Answer:
c=2;
Explanation:
Note:
However you cannot give like --2. Because -- operator can only be
applied to variables as a decrement operator (eg., i--). 2 is a
constant and not a variable.
130
10/7/16
q132
#define int char
main(){
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
Answer:
sizeof(i)=1
Explanation:
Since the #define replaces the string int by
the macro char
131
10/7/16
q133
main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
Answer:
hai
Explanation:
\n - newline
\b - backspace
\r - linefeed
132
10/7/16
q134
#define a 10
main()
{
#define a 50
printf("%d",;
}
Answer:
50
Explanation:
The preprocessor directives can be redefined anywhere in
the program. So the most recently assigned value will be
taken.
133
10/7/16
q135
#define clrscr() 100
main(){
clrscr();
printf("%d\n",clrscr());
}
Answer:
100
Explanation:
Preprocessor executes as a seperate pass before the execution of the compiler. So textual
replacement of clrscr() to 100 occurs.The input program to compiler looks like this :
main()
{
100;
printf("%d\n",100);
}
134
10/7/16
q136
main(){
printf("%p",main);
}
Answer:
Some address will be printed.
Explanation:
Function names are just addresses (just like
array names are addresses).main() is also a
function. So the address of function main will
be printed. %p in printf specifies that the
argument is an address. They are printed as
hexadecimal numbers.
135
10/7/16
q137
void main(){
int i=5;
printf("%d",i+++++i);
}
Answer:
Compiler Error
Explanation:
The expression i+++++i is parsed as i ++ +
+ + i which is an illegal combination of
operators.
136
10/7/16
137
10/7/16