View Source Print ?: Predict The Output of The Below Program
View Source Print ?: Predict The Output of The Below Program
Question 1
view source
print?
#include <stdio.h>
int main()
{
printf("%d", main);
getchar();
return 0;
}
struct
{
char *name;
int (*funcptr)();
}
symtab[] = {
"func", func,
"anotherfunc", anotherfunc,
};
Question 2
view source
print?
#include <stdio.h>
int main()
{
printf("\new_c_question\by");
printf("\rgeeksforgeeks");
getchar();
return 0;
}
Output: geeksforgeeksl
Explanation: First printf prints “ew_c_questioy”. Second printf has \r in it so it goes back to start
of the line and starts printing characters.
Now try to print following without using any of the escape characters.
new c questions by
geeksforgeeks
Question 3
view source
print?
# include<stdio.h>
# include<stdlib.h>
void fun(int *a)
{
a = (int*)malloc(sizeof(int));
}
int main()
{
int *p;
fun(p);
*p = 6;
printf("%d\n",*p);
getchar();
return(0);
}
Output: 6
Explanation: It does not work. Try replacing “int *p;” with “int *p = NULL;” and it will try to
dereference a null pointer.
This is because fun() makes a copy of the pointer, so when malloc() is called, it is setting the
copied pointer to the memory location, not p. p is pointing to random memory before and after
the call to fun(), and when you dereference it, it will crash.
If you want to add memory to a pointer from a function, you need to pass the address of the
pointer (ie. double pointer).
Question 4
view source
print?
#include <stdio.h>
int main()
{
int i;
i = 1, 2, 3;
printf("i = %d\n", i);
getchar();
return 0;
}
Output: 1
The above program prints 1. Associativity of comma operator is from left to right, but = operator
has higher precedence than comma operator.
Therefore the statement i = 1, 2, 3 is treated as (i = 1), 2, 3 by the compiler.
view source
print?
#include <stdio.h>
int main()
{
int i;
i = (1, 2, 3);
printf("i = %d\n", i);
getchar();
return 0;
}
Question 5
view source
print?
#include <stdio.h>
int main()
{
int first = 50, second = 60, third;
third = first /* Will this comment work? */ + second;
printf("%d /* And this? */ \n", third);
getchar();
return 0;
}
view source
print?
#include<stdio.h>
p = q;
*p = 2;
int i = 0, j = 1;
int main()
{
f(&i, &j);
getchar();
return 0;
(A) 2 2
(B) 2 1
(C) 0 1
(D) 0 2
Answer (D)
See below f() with comments for explanation.
view source
print?
view source
print?
#include<stdio.h>
int main()
getchar();
return 0;
(A) -9
(B) 5
(C) 15
(D) 19
Answer (C)
f() is a recursive function which adds f(a+1, n-1) to *a if *a is even. If *a is odd then f() subtracts
f(a+1, n-1) from *a. See below recursion tree for execution of f(a, 6).
.
Please write comments if you find any of the answers/explanations incorrect, or you want to
share more information about the topics discussed above.
Question 1
view source
print?
#include<stdio.h>
#define R 10
#define C 20
int main()
int (*p)[R][C];
printf("%d", sizeof(*p));
getchar();
return 0;
Output: 10*20*sizeof(int) which is “800″ for compilers with integer size as 4 bytes.
The pointer p is de-referenced, hence it yields type of the object. In the present case, it is an array
of array of integers. So, it prints R*C*sizeof(int).
Thanks to Venki for suggesting this solution.
Question 2
view source
print?
#include<stdio.h>
int main()
printf("%d", f(var,12));
getchar();
return 0;
Output: 100
The operator ## is called “Token-Pasting” or “Merge” Operator. It merges two tokens into one
token. So, after preprocessing, the main function becomes as follows, and prints 100.
view source
print?
int main()
printf("%d", var12);
getchar();
return 0;
Question 3
view source
print?
#include<stdio.h>
int main()
int y = ~0;
if(x == y)
printf("same");
else
printf("not same");
getchar();
return 0;
Question 1
view source
print?
#include <stdio.h>
char* fun()
return "awake";
int main()
{
getchar();
return 0;
Question 2
view source
print?
#include <stdio.h>
int main()
unsigned i ;
{
}
getchar();
return 0 ;
}
Output: Prints different output on different machines.
Explanation: (Thanks to Venki for suggesting this solution)
The format specifier is %d, converts the base address of string “11213141″ as an integer. The
base address of string depends on memory allocation by the compiler. The for loop prints same
address four times. Try to use C++ streams, you will see power of type system.
Question 1
view source
print?
#include<stdio.h>
int main(void)
int a = 1;
int b = 0;
printf("%d %d",a,b);
getchar();
return 0;
Question 2
view source
print?
#include<stdio.h>
int main()
getchar();
return 0;
Output: 6
&a is address of the whole array a[]. If we add 1 to &a, we get “base address of a[] + sizeof(a)”.
And this value is typecasted to int *. So ptr – 1 points to last element of a[]
Please write comments if you find any of the answers/explanations incorrect, or you want to
share more information about the topics discussed above.
Question 1
view source
print?
#include<stdio.h>
int main()
int a;
char *x;
x[0] = 1;
x[1] = 2;
printf("%d\n",a);
getchar();
return 0;
Answer: The output is dependent on endianness of a machine. Output is 513 in a little endian
machine and 258 in a big endian machine.
Let integers are stored using 16 bits. In a little endian machine, when we do x[0] = 1 and x[1] =
2, the number a is changed to 00000001 00000010 which is representation of 513 in a little
endian machine. The output would be same for 32 bit numbers also.
In a big endian machine, when we do x[0] = 1 and x[1] = 2, the number is changed to 00000001
00000010 which is representation of 258 in a big endian machine.
Question 2
view source
print?
int main()
int f = 0, g = 1;
int i;
{
f = f + g;
g = f - g;
}
getchar();
return 0;
Question 3
Explain functionality of following function.
view source
print?
int func(int i)
Answer: If n is odd then returns n, else returns (n-1). So if n is 12 then we get and if n is 11 then
we get 11.
Please write comments if you find any of the answers/explanations incorrect, or you want to
share more information about the topics discussed above.
Question 1
Predict the output of below program.
view source
print?
int main()
getchar();
return 0;
Output: 14
The string “geeksforgeeks” has 13 characters, but the size is 14 because compiler includes a
single ‘\0′ (string terminator) when char array size is not explicitly mentioned.
Question 2
In below program, what would you put in place of “?” to print “geeks”. Obviously, something
other than “geeks”.
view source
print?
int main()
printf("%s", ?);
getchar();
return 0;
Answer: (arr+8)
The printf statement prints everything starting from arr+8 until it finds ‘\0’
Question 3
Predict the output of below program.
view source
print?
int main()
int x, y = 5, z = 5;
x = y==z;
printf("%d", x);
getchar();
return 0;
The crux of the question lies in the statement x = y==z. The operator == is executed before =
because precedence of comparison operators (<=, >= and ==) is higher than assignment operator
=.
The result of a comparison operator is either 0 or 1 based on the comparison result. Since y is
equal to z, value of the expression y == z becomes 1 and the value is assigned to x via the
assignment operator.
Question 4
Predict the output of below program.
view source
print?
int main()
getchar();
return 0;
Question 1
view source
print?
while(*++str1);
return (str1-str2);
}
int main()
printf("%d", fun(str));
getchar();
return 0;
Output: 13
Inside fun(), pointer str2 is initialized as str1 and str1 is moved till ‘\0’ is reached (note ; after
while loop). So str1 will be incremented by 13 (assuming that char takes 1 byte).
Question 2
view source
print?
p = &q;
}
int main()
int r = 20;
int *p = &r;
fun(p);
printf("%d", *p);
getchar();
return 0;
Output: 20
Inside fun(), q is a copy of the pointer p. So if we change q to point something else then p
remains unaffected.
Question 3
view source
print?
*p = &q;
}
int main()
int r = 20;
int *p = &r;
fun(&p);
printf("%d", *p);
getchar();
return 0;
Output 10
Note that we are passing address of p to fun(). p in fun() is actually a pointer to p in main() and
we are changing value at p in fun(). So p of main is changed to point q of fun(). To understand it
better, let us rename p in fun() to p_ref or ptr_to_p
view source
print?
Also, note that the program won’t cause any problem because q is a static variable. Static
variables exist in memory even after functions return. For an auto variable, we might have seen
some weird output because auto variable may not exist in memory after functions return.
Question 1
view source
print?
#include<stdio.h>
int main()
typedef int i;
i a = 0;
printf("%d", a);
getchar();
return 0;
Output: 0
There is no problem with the program. It simply creates a user defined type i and creates a
variable a of type i.
Question 2
view source
print?
#include<stdio.h>
int main()
int j = 10;
i *a = &j;
printf("%d", **a);
getchar();
return 0;
}
Output: Compiler Error -> Initialization with incompatible pointer type.
The line typedef int *i makes i as type int *. So, the declaration of a means a is pointer to a
pointer. The Error message may be different on different compilers.
Question 3
view source
print?
#include<stdio.h>
int main()
int j;
i a = &j;
printf("%d", *a);
getchar();
return 0;
Question 1
view source
print?
int main()
int c=5;
printf("%d\n%d\n%d", c, c <<= 2, c >>= 2);
getchar();
References:
http://gcc.gnu.org/onlinedocs/gcc/Non_002dbugs.html
Question 2
view source
print?
int main()
char *p = arr;
if(&p == &arr)
printf("Same");
else
printf("Not same");
getchar();
view source
print?
int main()
char *p = arr;
if(p == &arr)
printf("Same");
else
printf("Not same");
getchar();
Question 3
view source
print?
int main()
char *p = arr;
getchar();
Output 4 3
sizeof(arr) returns the amount of memory used by all elements in array
and sizeof(p) returns the amount of memory used by the pointer variable itself.
Question 4
view source
print?
int x = 0;
int f()
return x;
int g()
int x = 1;
return f();
int main()
printf("%d", g());
printf("\n");
getchar();
Output: 1
In C, variables are always statically (or lexically) scoped. Binding of x inside f() to global
variable x is defined at compile time and not dependent on who is calling it. Hence, output for
the above program will be 0.
On a side note, Perl supports both dynamic ans static scoping. Perl’s keyword “my” defines a
statically scoped local variable, while the keyword “local” defines dynamically scoped local
variable. So in Perl, similar (see below) program will print 1.
view source
print?
$x = 0;
sub f
return $x;
sub g
print g()."\n";
view source
print?
#include<stdio.h>
int main()
int x = 5, p = 10;
printf("%*d", x, p);
getchar();
return 0;
Output: 10
Explanation:
Please see standard printf function definition
format: String that contains the text to be written to stdout. It can optionally contain embedded
format tags that are substituted by the values specified in subsequent argument(s) and formatted
as requested. The number of arguments following the format parameters should at least be as
much as the number of format tags. The format tags follow this prototype:
%[flags][width][.precision][length]specifier
So, in the above example 5 is precision and 10 is the actual value to be printed. (Thanks to Ajay
Mishra for providing the solution)
Question 2
view source
print?
int main()
while(*ptr != '\0')
++*ptr++;
getchar();
return 0;
}
Output: hffltgpshfflt
Explanation:
The crust of this question lies in expression ++*ptr++.
If one knows the precedence and associativity of the operators then there is nothing much left.
Below is the precedence of operators.
Postfixx ++ left-to-right
Prefix ++ right-to-left
Dereference * right-to-left
Question 3
view source
print?
int main()
printf("%d\n", i);
getchar();
return 0;
Output: -128
Explanation:
Here, the first thing to be noticed is the semi-colon in the end of for loop. So basically, there’s no
body for the for loop. And printf will print the value of i when control comes out of the for loop.
Also, notice that the first statement i.e. initializer in the for loop is not present. But i has been
initialized at the declaration time. Since i is a signed character, it can take value from -128 to
127. So in the for loop, i will keep incrementing and the condition is met till roll over happens.
At the roll over, i will become -128 after 127, in that case condition is not met and control comes
out of the for loop.
Question 4
view source
print?
#include <stdio.h>
fun(argv);
getchar();
return 0;
Explanation:
Parameter passed to fun() and parameter expected in definition are of incompatible types. fun()
expects const char** while passed parameter is of type char **.
Question 1
view source
print?
void main()
while(1){
if(printf("%d",printf("%d")))
break;
else
continue;
}
Output:
Can’t be predicted
Explanation:
The condition in while loop is 1 so at first shot it looks infinite loop. Then there are break and
continue in the body of the while loop, so it may not be infinite loop. The break statement will be
executed if the condition under if is met, otherwise continue will be executed. Since there’s no
other statements after continue in the while loop, continue doesn’t serve any purpose. In fact it is
extraneous. So let us see the if condition. If we look carefully, we will notice that the condition
of the if will be met always, so break will be executed at the first iteration itself and we will
come out of while loop. The reason why the condition of if will be met is printf function.
Function printf always returns the no. of bytes it has output. For example, the return value of
printf(“geeks”) will be 5 because printf will output 5 characters here. In our case, the inner printf
will be executed first but this printf doesn’t have argument for format specifier i.e. %d. It means
this printf will print any arbitrary value. But notice that even for any arbirary value, the no. of
bytes output by inner printf would be non-zero. And those no. of bytes will work as argument to
outer printf. The outer printf will print that many no. of bytes and return non-zero value always.
So the condition for if is also true always. Therefore, the while loop be executed only once. As a
side note, even without outer printf also, the condition for if is always true.
Question 2
view source
print?
main()
while(i-->=0)
printf("%u ",i);
Output:
9 8 7 6 5 4 3 2 1 0 4294967295 4294967294 …… (on a machine where int is 4 bytes long)
Explanation:
Let us examine the condition of while loop. It is obvious that as far as the condition of while loop
is met, printf will be executed. There are two operators in the condition of while loop: post-
decrement operator and comparison operator. From operator precedence, we know that unary
operator post-decrement has higher priority than comparison operator. But due to post-decrement
property, the value of i will be decremented only after it had been used for comparison. So at the
first iteration, the condition is true because 10>=0 and then i is decremented. Therefore 9 will be
printed. Similarly the loop continues and the value of i keeps on decrementing. Let us see what
what happen when condition of while loop becomes 0 >= 0. At this time, condition is met and i
is decremented. Since i is unsigned integer, the roll-over happens and i takes the value of the
highest +ve value an unsigned int can take. So i is never negative. Therefore, it becomes infinite
while loop.
As a side note, if i was signed int, the while loop would have been terminated after printing the
highest negative value.
Question 3
view source
print?
main()
{
int x,y=2,z,a;
if(x=y%2) z=2;
a=2;
printf("%d %d ",z,x);
Output:
0
Explanation:
This question has some stuff for operator precedence. If the condition of if is met, then z will be
initialized to 2 otherwise z will contain garbage value. But the condition of if has two operators:
assignment operator and modulus operator. The precedence of modulus is higher than
assignment. So y%2 is zero and it’ll be assigned to x. So the value of x becomes zero which is
also the effective condition for if. And therefore, condition of if is false.
Question 4
view source
print?
main()
int a[10];
printf("%d",*a+1-*a+3);
Output: 4
Explanation:
From operator precedence, de-reference operator has higher priority than addition/subtraction
operator. So de-reference will be applied first. Here, a is an array which is not initialized. If we
use a, then it will point to the first element of the array. Therefore *a will be the first element of
the array. Suppose first element of array is x, then the argument inside printf becomes as follows.
It’s effective value is 4.
x+1–x+3=4
Question 5
view source
print?
main()
int x=3,y=4;
printf("%d",prod(x+2,y-1));
Output:
10
Explanation:
This program deals with macros, their side effects and operator precedence. Here prod is a macro
which multiplies its two arguments a and b. Let us take a closer look.
prod(a, b) = a*b
prod(x+2, y-1) = x+2*y-1 = 3+2*4-1 = 3+8-1=10
If the programmer really wanted to multiply x+2 and y-1, he should have put parenthesis around
a and b as follows.
prod(a,b) = (a)*(b)
Question 1
view source
print?
#include‹stdio.h›
int main()
{
struct site
{
};
printf("%d",ptr->x);
printf("%s",ptr->name);
getchar();
return 0;
Output:
Compiler error
Explanation:
Note the difference between structure/union declaration and variable declaration. When you
declare a structure, you actually declare a new data type suitable for your purpose. So you cannot
initialize values as it is not a variable declaration but a data type declaration.
Reference:
http://www.lix.polytechnique.fr/~liberti/public/computing/prog/c/C/SYNTAX/struct.html
Question 2
view source
print?
int main()
'r','g','e','e','k','s'};
return 0;
Output:
geeksforgeeks
Explanation:
We have created a 3D array that should have 2*3*3 (= 18) elements, but we are initializing only
13 of them. In C when we initialize less no of elements in an array all uninitialized elements
become ‘\0′ in case of char and 0 in case of integers.
Question 3
view source
print?
int main()
ptr1 = &str[3];
ptr2 = str + 5;
printf("%s", str);
getchar();
return 0;
}
Output:
heejs
forgeeks
Explanation:
Initially ptr1 points to ‘k’ and ptr2 points to ‘\n’ in “geeks\nforgeeks”. In print statement value at
str is incremented by 1 and value at ptr1 is decremented by 1. So string becomes
“heejs\nforgeeks” .
First print statements newline character. and next print statement prints “heejs\nforgeeks”.
Question 4
view source
print?
#include <stdio.h>
int fun(int n)
int i, j, sum = 0;
for(i = 1;i<=n;i++)
for(j=i;j<=i;j++)
sum=sum+j;
return(sum);
int main()
printf("%d", fun(15));
getchar();
return 0;
}
Output: 120
Explanation: fun(n) calculates sum of first n integers or we can say it returns n(n+1)/2.
Question 5
view source
print?
#include <stdio.h>
int main()
int c = 5, no = 10;
do {
no /= c;
} while(c--);
return 0;
Explanation: There is a bug in the above program. It goes inside the do-while loop foe c = 0 also.
Be careful when you are using do-while loop like this!!
Question 1
view source
print?
char *getString()
{
return str;
int main()
printf("%s", getString());
getchar();
Question 2
view source
print?
int main()
if(--i){
main();
printf("%d ",i);
}
Output: 0 0 0 0
Explanation: Since i is a static variable and is stored in Data Section, all calls to main share same
i.
Question 3
view source
print?
int main()
printf("%d ",var--);
if(var)
main();
Output: 5 4 3 2 1
Explanation: Same as previous question. The only difference here is, sequence of calling main
and printf is changed, therefore different output.
Question 4
view source
print?
int main()
int x;
printf("%d",scanf("%d",&x));
return 1;
Output: 1
scanf returns the no. of inputs it has successfully read.
Question 5
view source
print?
# include <stdio.h>
int main()
int i=0;
{
switch(i)
{
case 0:
i+=5;
case 1:
i+=2;
case 5:
i+=5;
default:
i+=4;
break;
}
}
getchar();
return 0;
}
Output: 16 21
Explanation:
Initially i = 0. Since case 0 is true i becomes 5, and since there is no break statement till last
statement of switch block, i becomes 16. Now in next iteration no case is true, so execution goes
to default and i becomes 21.
In C, if one case is true switch block is executed until it finds break statement. If no break
statement is present all cases are executed after the true case. If you want to know why switch is
implemented like this, well this implementation is useful for situations like below.
switch (c)
{
case 'a':
case 'e':
case 'i' :
case 'o':
case 'u':
printf(" Vowel character");
break;
default :
printf("Not a Vowel character");; break;
}
Question 1
view source
print?
#include<stdio.h>
int fun()
return num--;
int main()
}
getchar();
return 0;
Output: 38 35 32 29 26 23 20 17 14 11 8 5 2
Since num is static in fun(), the old value of num is preserved for subsequent functions calls.
Also, since the statement return num– is postfix, it returns the old value of num, and updates the
value for next function call.
Question 2
view source
print?
#include<stdio.h>
int main()
char **p;
p = s;
getchar();
return 0;
}
Output: nowledge nowledge s
Let us consider the expression ++*p in first printf(). Since precedence of prefix ++ and * is
same, associativity comes into picture. *p is evaluated first because both prefix ++ and * are
right to left associative. When we increment *p by 1, it starts pointing to second character of
“knowledge”. Therefore, the first printf statement prints “nowledge”.
Let us consider the expression *p++ in second printf() . Since precedence of postfix ++ is higher
than *, p++ is evaluated first. And since it’s a psotfix ++, old value of p is used in this
expression. Therefore, second printf statement prints “nowledge”.
In third printf statement, the new value of p (updated by second printf) is used, and third printf()
prints “s”.
1.void main()
{
struct a
{
char ch[10];
char *str;
};
struct a s1={"Hyderabad","Bangalore"};
printf("\n%c%c",s1.ch[0],*s1.str);
printf("\n%s%s",s1.ch,s1.str);
getch();
}
4.void main()
{
int i;
clrscr();
for(i=1;i<6;++i)
switch(i)
{
case 1:
case 2: printf("%d,",i++);break;
case 3: continue;
case 4: printf("%d,",i);
}
printf("%d",i);
getch();
}
file://Ans: 1,4,6
Ans: C
A. 3
B. 2
C. 1
D. 0
A. SOUNDEX
B. DECODE
C. LIKE
D. HAVING
MCQ of c programming 2
MCQ of c programming 4
MCQ of c programming 7
Q. 1 . void main()
{
int i,j;
for(i=0,j=0;i<2,j<2;i++,j++) i="5;" a="1,b="2;" a="="2)" b="="3)"
x="2,y="3;" t="x;" x="*y;" y="t;" i="9;" i="0;i<3;i++)" x="3.7;"
y="1.5;">1.5)
printf("fool");
else
printf("stupid");
}
a . fool
b . stupid
c . garbage value
d . None of these
Q. 11 . Most of the errors blamed on a computer are actually due
to
a . programming errors
b . hardware damage
c . data entry errors
d . physical conditions
Q. 12 . Find the output.
void main()
{
int i;
for(i=-9;!i;i++);
printf("%d",-i);
}
a . 8
b . 9
c . 0
d . 1
Q. 13 . Switch-case statement does not implement on
a . non exclusive case
b . mutually exclusive case
c . mutually non exclusive case
d . exclusive case
Q. 14 . Find out the output.
void main()
{
int i=98;
while(100-i++)
printf("%u",i);
switch(i)
case ‘e’:
printf("Fool");
}
a . 98 99 100
b . 99 100
c . 99 100 Fool
d . Expression syntax error
Q. 15 . Find out the output
void main()
{
if("lakshya"=="lakshya")
printf("equal");
else
printf("not equal");
}
a . equal
b . not equal
c . Compile time error
d . None of these
Q. 16 . Find the output.
void main()
{
char s=’A’;
char a=’a’;
printf("%d",s-a);
}
a . -32
b . -18
c . Error
d . None of these
Q. 17 . Find out the true statement.
a . A union variable can be assigned to another union variable.
b . The address of union variable can be extracted by using &
operator.
c . A function can return a pointer to the union.
d . All the above
Q. 18 . Find out the output
#define min(a,b) ((a)<(b))?(a):(b) main() { int i=0,a[20],*ptr;
ptr=a; while(min(ptr++,&a[9])<&a[8]) i=i+1; printf("i=%d\n",i); }
a . 7 b . 6 c . 5 d . compile time erro Q. 19 . To flush all
output streams we can write a . fflush(stdout) b . fflush(NULL) c
. fflush(ALL) d . None of these Q. 20 . Find the correct output
void main() { int a[]={1,2,3,4,5},i; for(i=0;i<5;i++) p="hai"
p="’H’;" q="’B’" a="10;" a="(*a)*(*a);" x="12;" y="x;" i="1;"
c="’l’;" p="strchr(s,c);" x="(y="3,y+1);" a="5,b="4,c="10;">b) ?
&a : &b) = (a+b>c);
printf("%d\t%d",a,b);
}
a . 5 4
b . Error, lvalue required
c . 0 4
d . 4 0
MCQ of c programming 9
MCQ of c programming 14
Q. 1 . Find the correct output
void main()
{
int a=30,b=20,c;
c=(float)a/b;
printf("%d",c);
}
a . 1
b . 1.500000
c . 1.000000
d . Error
Q. 2 . State the correct statement.
struct employee
{
int eid;
char name[23];
float salary;
}emp={278,"p.das",5000.000},*p=&emp;
How to access eid in the above structure?
I. *p->eid II. p.eid III. (*p).eid IV. (*p)->eid
a . Only I
b . Only III
c . Both I & III
d . All of the above
Q. 3 . Find out the output
void main()
{
int ch=48;
if(ch)
{
printf("valid");
break;
}
else
printf("invalid");
}
a . valid
b . invalid
c . No output
d . None of these
Q. 4 . Find out the output
void main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}
a . Error
b . 1==1 is TRUE
c . 0==1 is FALSE
d . Garbage Output
Q. 5 . what is the o/p in turbo compiler?
struct stud
{
int x:18;
char *y;
f loat z;
}s1;
void main()
{
printf("%d",sizeof(s1));
}
a . 7
b . 1
c . 8
d . Error
Q. 6 . Find the output
void main()
{
int i=-3,j=2,k=0,m;
m=++ && j++ && ++k;
printf("\n%d, %d, %d, %d",i,j,k,m);
}
a . -2,-3,1,1
b . -3, 2, 0,1
c . -2, 3, 0,1
d . -2, 3, 1,0
Q. 7 . Find the output.
void main()
{
int x=5,y=6;
do{
x=x+y;
y=x-y;
x=x-y;
}while(x0)
rev(--n);
printf("%d",n);
}
a . 0012
b . 123
c . 012
d . None of these
Q. 9 . RAM is made up of
a . registers
b . diodes
c . capacitors
d . flip-flops
Q. 10 . The default memory model in C is
a . tiny
b . small
c . medium
d . compact
Q. 11 . Find the correct output
void main()
{
int i=5;
i=i++ + ++i;
printf("%d",i);
}
a . 11
b . 12
c . 13
d . None of these
Q. 12 . Find out the output
int i = 4;
void main()
{
switch (i)
{
default:
;
case 3:
i += 5;
if ( i == 8);
{
i++;
if (i = 9);
i *= 2;
}
i -= 4;
break;
case 8:
i += 5;
break;
}
printf("i = %d\n", i);
}
a . i=5
b . i=16
c . i=18
d . i=14
Q. 13 . Find out the output.
void main()
{
printf("%d",sizeof(5.3));
}
a . 2
b . 4
c . 8
d . Suffering
Q. 14 . A file pointer is
a . a stream pointer
b . a buffer pointer
c . a pointer to a FILE data type
d . All of the above
Q. 15 . Find out the output
void main()
{
char p[6];
static char *q;
q=p;
*q="Hello";
printf("%s",q);
}
a . Garbage output
b . Hello
c . Error
d . None of these
Q. 16 . Find out the output
void main()
{
int x[]={1,2,3,4,5,6};
int *p,q,r;
p=x+3;
q=5;r=4;
printf("%d",p[(q>r)-2]);
}
a . 4
b . 3
c . 5
d . Error
Q. 17 . What is the formula to find real address from 16-bit
physical address?
a . segment address*16+offset address
b . segment address+offset address *16
c . segment address*10+offset address
d . segment address+offset address *10
Q. 18 . The function strcmp(s1,s2) returns negative value if
a . Length of s1 is less than s2
b . Length of s2 is less than s1
c . Length of s1 is less than or equal to s2
d . Both s1 and s2 are same.
Q. 19 . Find the output.
void main()
{
int a,b,sum=0;
sum= (a=5,b=9,++a+ ++b);
printf("%d", sum);
}
a . 16
b . 5
c . Expression syntax error
d . Error, lvalue required
Q. 20 . Find out the output
#define Str(x) #x
#define Xstr(x) Str(x)
#define OP plus
void main()
{
int *opname = Xstr(OP);
printf("%s",opname);
}
a . plus
b . No output
c . It will show compilation error
d . No output
Q. 21 . void main() { int i,j=1; for(i=1;i<5;i++) i="="2"
j="="2)" i="1;" i="="2)" x="5;" temp="a;" a="b;" b="temp;"
a="5,b="6,temp;"> b)
swap(a,b);
printf("a=%d b=%d",a,b);
}
a . a=5 b=6
b . a=6 b=5
c . a=6 b=0
d . None of these
Q. 26 . Find out the output
main()
{
static int val=7;
int data;
if (--val)
{
data=main()+val;
printf("%d ",data);
}
return 0;
}
a . Compile time Error
b . Infinite loop
c . 1 2 3 4 5 6
d . 0 0 0 0 0 0
Q. 27 . Find out the output.
void main()
{
int i=5,j=5;
i= i++*i++*i++*i++;
printf("i=%d ",i);
j= ++j*++j*++j*++j;
printf("j=%d",j);
}
a . i=1680 j=1680
b . i=629 j=6561
c . i=1681 j=3024
d . Compile time Error
Q. 28 . State the true statement.
a . A circular list doesn’t have a natural first or last node.
b . It is always desirable keep an extra node at the front of the
list.
c . A stack can’t be represented in memory using linear array.
d . All of the above
Q. 29 . Find the output
#define float int
void main()
{
int x=10;
float y=3;
y=x%y;
printf("%f",y);
}
a . 0
b . 1
c . 1.000000
d . Error, floating point format not linked
Q. 30 . Find the output
void main()
{
int *q,**p,x=4;
q=&x;
p=&q;
(**p)++;
++*p;
printf("%d",**p);
}
a . 5
b . 6
c . Garbage output
d . Error, non portable pointer conversion
MCQ of c programming 15