C Programming :: Pointers - Discussion
1. What is (void*)0?
[A]. Representation of NULL pointer
[B]. Representation of void pointer
[C]. Error
[D]. None of above
Answer: Option A
2. Can you combine the following two statements into one?
char *p;
p=(char*) malloc(100);
A.char p = *malloc(100);
B.char *p = (char) malloc(100);
C.char *p = (char*)malloc(100);
D.char *p = (char *)(malloc*)(100);
Answer: Option C
3. In which header file is the NULL macro defined?
A.stdio.h
B.stddef.h
C.stdio.h and stddef.h
D.math.h
Answer: Option C
Explanation:The macro "NULL" is defined in locale.h, stddef.h, stdio.h, stdlib.h, string.h, time.h, and wchar.h.
4.How many bytes are occupied by near, far and huge pointers (DOS)?
A.near=2 far=4 huge=4
B.near=4 far=8 huge=8
C.near=2 far=4 huge=8
D.near=4 far=4 huge=8
Answer: Option A
Explanation:near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every pointers is 4 bytes long.
5. If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
A..
B.&
C.*
D.->
Answer: Option D
Explanation:No answer description available for this question.
6.What would be the equivalent pointer expression for referring the array element a[i][j][k][l]A.((((a+i)+j)+k)+l)
B.*(*(*(*(a+i)+j)+k)+l)
C.(((a+i)+j)+k+l)
D.((a+i)+j+k+l)
Answer: Option B
Explanation:No answer description available for this question.
7. A pointer is
A.A keyword used to create variables
B.A variable that stores address of an instruction
C.A variable that stores address of other variable
D.All of the above
Answer: Option C
Explanation:No answer description available for this question. Let us discuss.
8. The operator used to get value at address stored in a pointer variable is
A.*
B.&
C.&&
D.||
Answer: Option A
Explanation:No answer description available for this questions
9. What will be the output of the program ?
#include<stdio.h>
int main()
{
static char *s[] = {"black", "white", "pink", "violet"};
char **ptr[] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
++p;
printf("%s", **p+1);
return 0;
}
A.ink
B.ack
C.ite
D.let
Answer: Option A
10. What will be the output of the program ?
#include<stdio.h>
int main()
{
int i=3, *j, k;
j = &i;
printf("%d\n", i**j*i+*j);
return 0;
}
A.30
B.27
C.9
D.3
Answer: Option A
11. What will be the output of the program ?
#include<stdio.h>
int main()
{
int x=30, *y, *z;
y=&x; /* Assume address of x is 500 and integer is 4 byte size */
z=y;
*y++=*z++;
x++;
printf("x=%d, y=%d, z=%d\n", x, y, z);
return 0;
}
A.x=31, y=502, z=502
B.x=31, y=500, z=500
C.x=31, y=498, z=498
D.x=31, y=504, z=504
Answer: Option D
12. What will be the output of the program ?
#include<stdio.h>
int main()
{
char str[20] = "Hello";
char *const p=str;
*p='M';
printf("%s\n", str);
return 0;
}
A.Mello
B.Hello
C.HMello
D.MHello
Answer: Option A
13. What will be the output of the program If the integer is 4bytes long?
#include<stdio.h>
int main()
{
int ***r, **q, *p, i=8;
p = &i;
q = &p;
r = &q;
printf("%d, %d, %d\n", *p, **q, ***r);
return 0;
}
A.8, 8, 8
B.4000, 4002, 4004
C.4000, 4004, 4008
D.4000, 4008, 4016
Answer: Option A
14. What will be the output of the program ?
#include<stdio.h>
void fun(void *p);
int i;
int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
A.Error: cannot convert from void** to int**
B.Garbage value
C.0
D.No output
Answer: Option C
15. What will be the output of the program ?
#include<stdio.h>
int main()
{
char *str;
str = "%s";
printf(str, "K\n");
return 0;
}
A.Error
B.No output
C.K
D.%s
Answer: Option C
16.What will be the output of the program ?
#include<stdio.h>
int *check(static int, static int);
int main()
{
int *c;
c = check(10, 20);
printf("%d\n", c);
return 0;
}
int *check(static int i, static int j)
{
int *p, *q;
p = &i;
q = &j;
if(i >= 45)
return (p);
else
return (q);
}
A.10
B.20
C.Error: Non portable pointer conversion
D.Error: cannot use static for function parameters
Answer: Option D
17.What will be the output of the program if the size of pointer is 4-bytes?
#include<stdio.h>
int main()
{
printf("%d, %d\n", sizeof(NULL), sizeof(""));
return 0;
}
A.2, 1
B.2, 2
C.4, 1
D.4, 2
Answer: Option C
Explanation:In TurboC, the output will be 2, 1 because the size of the pointer is 2 bytes in 16-bit platform.
But in Linux, the output will be 4, 1 because the size of the pointer is 4 bytes.
This difference is due to the platform dependency of C compiler.
18.What will be the output of the program ?
#include<stdio.h>
int main()
{
void *vp;
char ch=74, *cp="JACK";
int j=65;
vp=&ch;
printf("%c", *(char*)vp);
vp=&j;
printf("%c", *(int*)vp);
vp=cp;
printf("%s", (char*)vp+2);
return 0;
}
A.JCK
B.J65K
C.JAK
D.JACK
Answer: Option D
19.What will be the output of the program?
#include<stdio.h>
int main()
{
int arr[2][2][2] = {10, 2, 3, 4, 5, 6, 7, 8};
int *p, *q;
p = &arr[1][1][1];
q = (int*) arr;
printf("%d, %d\n", *p, *q);
return 0;
}
A.8, 10
B.10, 2
C.8, 1
D.Garbage values
Answer: Option A
20. What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?
#include<stdio.h>
int main()
{
int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1));
return 0;
}
A.448, 4, 4
B.520, 2, 2
C.1006, 2, 2
D.Error
Answer: Option C
21. What will be the output of the program?
#include<stdio.h>
int main()
{
int arr[3] = {2, 3, 4};
char *p;
p = arr;
p = (char*)((int*)(p));
printf("%d, ", *p);
p = (int*)(p+1);
printf("%d", *p);
return 0;
}
A.2, 3
B.2, 0
C.2, Garbage value
D.0, 0
Answer: Option B
22.hat will be the output of the program ?
#include<stdio.h>
int main()
{
char *str;
str = "%d\n";
str++;
str++;
printf(str-2, 300);
return 0;
}
A.No output
B.30
C.3
D.300
Answer: Option D
23. What will be the output of the program ?
#include<stdio.h>
int main()
{
printf("%c\n", 7["IndiaBIX"]);
return 0;
}
A.Error: in printf
B.Nothing will print
C.print "X" of IndiaBIX
D.print "7"
Answer: Option C
24. What will be the output of the program ?
#include<stdio.h>
int main()
{
char str[] = "peace";
char *s = str;
printf("%s\n", s++ +3);
return 0;
}
A.peace
B.eace
C.ace
D.ce
Answer: Option D
25. What will be the output of the program ?
#include<stdio.h>
int main()
{
char *p;
p="hello";
printf("%s\n", *&*&p);
return 0;
}
A.llo
B.hello
C.ello
D.h
Answer: Option B
26. What will be the output of the program assuming that the array begins at location 1002?
#include<stdio.h>
int main()
{
int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2},
{2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
return 0;
}
A.1002, 2004, 4008, 2
B.2004, 4008, 8016, 1
C.1002, 1002, 1002, 1
D.Error
Answer: Option C
27. What will be the output of the program ?
#include<stdio.h>
power(int**);
int main()
{
int a=5, *aa; /* Address of 'a' is 1000 */
aa = &a;
a = power(&aa);
printf("%d\n", a);
return 0;
}
power(int **ptr)
{
int b;
b = **ptr***ptr;
return (b);
}
A.5
B.25
C.125
D.Garbage value
Answer: Option B
28. What will be the output of the program ?
#include<stdio.h>
int main()
{
char str1[] = "India";
char str2[] = "BIX";
char *s1 = str1, *s2=str2;
while(*s1++ = *s2++)
printf("%s", str1);
printf("\n");
return 0;
}
A.IndiaBIX
B.BndiaBIdiaBIXia
C.India
D.(null)
Answer: Option B
29.What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
int i, n;
char *x="Alice";
n = strlen(x);
*x = x[n];
for(i=0; i<=n; i++)
{
printf("%s ", x);
x++;
}
printf("\n", x);
return 0;
}
A.Alice
B.ecilA
C.Alice lice ice ce e
D.lice ice ce e
Answer: Option D
Explanation:If you compile and execute this program in windows platform with Turbo C, it will give "lice ice ce e".
It may give different output in other platforms (depends upon compiler and machine). The online C compiler given in this site will give the Option C as output (it runs on Linux platform).
30.What will be the output of the program ?
#include<stdio.h>
int main()
{
int i, a[] = {2, 4, 6, 8, 10};
change(a, 5);
for(i=0; i<=4; i++)
printf("%d, ", a[i]);
return 0;
}
void change(int *b, int n)
{
int i;
for(i=0; i<n; i++)
*(b+1) = *(b+i)+5;
}
A.7, 9, 11, 13, 15
B.2, 15, 6, 8, 10
C.2 4 6 8 10
D.3, 1, -1, -3, -5
Answer: Option B
31.If the size of integer is 4bytes, What will be the output of the program?
#include<stdio.h>
int main()
{
int arr[] = {12, 13, 14, 15, 16};
printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
return 0;
}
A.10, 2, 4
B.20, 4, 4
C.16, 2, 2
D.20, 2, 2
Answer: Option B
32. What will be the output of the program ?
#include<stdio.h>
int main()
{
union a
{
int i;
char ch[2];
};
union a u;
u.ch[0]=3;
u.ch[1]=2;
printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i);
return 0;
}
A.3, 2, 515
B.515, 2, 3
C.3, 2, 5
D.515, 515, 4
Answer: Option A
Explanation:The system will allocate 2 bytes for the union.
The statements u.ch[0]=3; u.ch[1]=2; store data in memory as given below.
33. What will be the output of the program ?
#include<stdio.h>
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
A.10
B.20
C.30
D.0
Answer: Option B
34. What will be the output of the program ?
#include<stdio.h>
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit={1, 2, 13};
printf("%d, %d, %d\n", bit.bit1, bit.bit3, bit.bit4);
return 0;
}
A.1, 2, 13
B.1, 4, 4
C.-1, 2, -3
D.-1, -2, -13
Answer: Option C
Explanation:Note the below statement inside the struct:
int bit1:1; --> 'int' indicates that it is a SIGNED integer.
For signed integers the leftmost bit will be taken for +/- sign.
If you store 1 in 1-bit field:
he left most bit is 1, so the system will treat the value as negative number.
The 2's complement method is used by the system to handle the negative values.
herefore, the data stored is 1. The 2's complement of 1 is also 1 (negative).
herefore -1 is printed.If you store 2 in 4-bits field:Binary 2: 0010 (left most bit is 0, so system will treat it as positive value)
0010 is 2 Therefore 2 is printed.f you store 13 in 4-bits field:Binary 13: 1101 (left most bit is 1, so system will treat it as negative value)
Find 2's complement of 1101:
1's complement of 1101 : 0010
2's complement of 1101 : 0011 (Add 1 to the result of 1's complement)
0011 is 3 (but negative value)Therefore -3 is printed.
35.what will be the output of the program in 16 bit platform (Turbo C under DOS) ?
#include<stdio.h>
int main()
{
struct value
{
int bit1:1;
int bit3:4;
int bit4:4;
}bit;
printf("%d\n", sizeof(bit));
return 0;
}
A.1
B.2
C.4
D.9
Answer: Option B
Explanation:Since C is a compiler dependent language, in Turbo C (DOS) the output will be 2, but in GCC (Linux) the output will be 4.
36. What will be the output of the program ?
#include<stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT);
return 0;
}
A.-1, 0, 1, 2, 3, 4
B.-1, 2, 6, 3, 4, 5
C.-1, 0, 6, 2, 3, 4
D.-1, 0, 6, 7, 8, 9
Answer: Option D
Explanation:No answer description available for this question. Let us discuss.
37. What will be the output of the program ?
#include<stdio.h>
int main()
{
enum status {pass, fail, absent};
enum status stud1, stud2, stud3;
stud1 = pass;
stud2 = absent;
stud3 = fail;
printf("%d %d %d\n", stud1, stud2, stud3);
return 0;
}
A.0, 1, 2
B.1, 2, 3
C.0, 2, 1
D.1, 3, 2
Answer: Option C
38. What will be the output of the program ?
#include<stdio.h>
int main()
{
int i=4, j=8;
printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j);
return 0;
}
A.12, 12, 12
B.112, 1, 12
C.32, 1, 12
D.-64, 1, 12
Answer: Option A
39. What will be the output of the program in Turbo C (under DOS)?
#include<stdio.h>
int main()
{
struct emp
{
char *n;
int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}
A.Error: Invalid structure assignment
B.DRAVID
C.Dravid
D.No output
Answer: Option B
40. What will be the output of the program in 16-bit platform (under DOS)?
#include<stdio.h>
int main()
{
struct node
{
int data;
struct node *link;
};
struct node *p, *q;
p = (struct node *) malloc(sizeof(struct node));
q = (struct node *) malloc(sizeof(struct node));
printf("%d, %d\n", sizeof(p), sizeof(q));
return 0;
}
A.2, 2
B.8, 8
C.5, 5
D.4, 4
41. What will be the output of the program ?
#include<stdio.h>
int main()
{
struct byte
{
int one:1;
};
struct byte var = {1};
printf("%d\n", var.one);
return 0;
}
A.1
B.-1
C.0
D.Error
Answer: Option B
Explanation:No answer description available for this question. Let us discuss.
42. What will be the output of the program ?
#include<stdio.h>
int main()
{
enum days {MON=-1, TUE, WED=6, THU, FRI, SAT};
printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT);
return 0;
}
A.-1, 0, 1, 2, 3, 4
B.Error
C.0, 1, 6, 3, 4, 5
D.0, 0, 6, 7, 8, 9
Answer: Option B
Explanation:Because ++ or -- cannot be done on enum value.
43. What will be the output of the program ?
#include<stdio.h>
struct course
{
int courseno;
char coursename[25];
};
int main()
{
struct course c[] = { {102, "Java"},
{103, "PHP"},
{104, "DotNet"} };
printf("%d ", c[1].courseno);
printf("%s\n", (*(c+2)).coursename);
return 0;
}
A.103 DotNet
B.102 Java
C.103 PHP
D.104 DotNet
Answer: Option A
44. What will be the output of the program given below in 16-bit platform ?
#include<stdio.h>
int main()
{
enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var;
printf("%d\n", sizeof(var));
return 0;
}
A.1
B.2
C.4
D.10
Answer: Option B
Explanation:No answer description available for this question. Let us discuss.
45. The keyword used to transfer control from a function back to the calling function is
A.switch
B.goto
C.go back
D.return
46. What is the notation for following functions?
1. int f(int a, float b)
{
/* Some code */
}
2. int f(a, b)
int a; float b;
{
/* Some code */
}
A. 1. KR Notation
2. ANSI Notation
B. 1. Pre ANSI C Notation
2. KR Notation
C. 1. ANSI Notation
2. KR Notation
D. 1. ANSI Notation
2. Pre ANSI Notation
Answer: Option C
Explanation:KR Notation means Kernighan and Ritche Notation.
47.How many times the program will print "IndiaBIX" ?
#include<stdio.h>
int main()
{
printf("IndiaBIX");
main();
return 0;
}
A.Infinite times
B.32767 times
C.65535 times
D.Till stack overflows
Answer: Option D
Explanation:A call stack or function stack is used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing.
A stack overflow occurs when too much memory is used on the call stack.
Here function main() is called repeatedly and its return address is stored in the stack. After stack memory is full. It shows stack overflow error.
48. What will be the output of the program in 16 bit platform (Turbo C under DOS)?
#include<stdio.h>
int main()
{
int fun();
int i;
i = fun();
printf("%d\n", i);
return 0;
}
int fun()
{
_AX = 1990;
}
A.Garbage value
B.0 (Zero)
C.1990
D.No output
Answer: Option C
Explanation:Turbo C (Windows): The return value of the function is taken from the Accumulator _AX=1990.
But it may not work as expected in GCC compiler (Linux).
49. What will be the output of the program?
#include<stdio.h>
void fun(int*, int*);
int main()
{
int i=5, j=2;
fun(&i, &j);
printf("%d, %d", i, j);
return 0;
}
void fun(int *i, int *j)
{
*i = *i**i;
*j = *j**j;
}A.5, 2
B.10, 4
C.2, 5
D.25, 4
Answer: Option D
Explanation: Step 1: int i=5, j=2; Here variable i and j are declared as an integer type and initialized to 5 and 2 respectively.
Step 2: fun(&i, &j); Here the function fun() is called with two parameters &i and &j (The & denotes call by reference. So the address of the variable i and j are passed. )
Step 3: void fun(int *i, int *j) This function is called by reference, so we have to use * before the parameters.
Step 4: *i = *i**i; Here *i denotes the value of the variable i. We are multiplying 5*5 and storing the result 25 in same variable i.
Step 5: *j = *j**j; Here *j denotes the value of the variable j. We are multiplying 2*2 and storing the result 4 in same variable j.
Step 6: Then the function void fun(int *i, int *j) return back the control back to main() function.
Step 7: printf("%d, %d", i, j); It prints the value of variable i and j.
Hence the output is 25, 4.
50.What will be the output of the program?
#include<stdio.h>
int i;
int fun();
int main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}
A.Hello
B.Hi Hello
C.No output
D.Infinite loop
Answer: Option A
Explanation:Step 1: int i; The variable i is declared as an integer type.
Step 1: int fun(); This prototype tells the compiler that the function fun() does not accept any arguments and it returns an integer value.
Step 1: while(i) The value of i is not initialized so this while condition is failed. So, it does not execute the while block.
Step 1: printf("Hello\n"); It prints "Hello".
Hence the output of the program is "Hello".
51. What will be the output of the program?
#include<stdio.h>
int reverse(int);
int main()
{
int no=5;
reverse(no);
return 0;
}
int reverse(int no)
{
if(no == 0)
return 0;
else
printf("%d,", no);
reverse (no--);
}
A.Print 5, 4, 3, 2, 1
B.Print 1, 2, 3, 4, 5
C.Print 5, 4, 3, 2, 1, 0
D.Infinite loop
52.What will be the output of the program?
#include<stdio.h>
void fun(int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main()
{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(--n);
printf("%d,", n);
fun(--n);
}
}
A.0, 2, 1, 0,
B.1, 1, 2, 0,
C.0, 1, 0, 2,
D.0, 1, 2, 0,
Answer: Option D
53.What will be the output of the program?
#include<stdio.h>
int sumdig(int);
int main()
{
int a, b;
a = sumdig(123);
b = sumdig(123);
printf("%d, %d\n", a, b);
return 0;
}
int sumdig(int n)
{
int s, d;
if(n!=0)
{
d = n%10;
n = n/10;
s = d+sumdig(n);
}
else
return 0;
return s;
}
A.4, 4
B.3, 3
C.6, 6
D.12, 12
Answer: Option C
54.What will be the output of the program?
#include<stdio.h>
int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B';
a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}
A.AB
B.BC
C.CD
D.No output
Answer: Option B
55.What will be the output of the program?
#include<stdio.h>
int main()
{
int fun(int);
int i = fun(10);
printf("%d\n", --i);
return 0;
}
int fun(int i)
{
return (i++);
}
A.9
B.10
C.11
D.8
Answer: Option A
Explanation:Step 1: int fun(int); Here we declare the prototype of the function fun().
Step 2: int i = fun(10); The variable i is declared as an integer type and the result of the fun(10) will be stored in the variable i.
Step 3: int fun(int i){ return (i++); } Inside the fun() we are returning a value return(i++). It returns 10. because i++ is the post-increement operator.
Step 4: Then the control back to the main function and the value 10 is assigned to variable i.
Step 5: printf("%d\n", --i); Here --i denoted pre-increement. Hence it prints the value 9.
56. What will be the output of the program?
#include<stdio.h>
int check (int, int);
int main()
{
int c;
c = check(10, 20);
printf("c=%d\n", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
A.Print 10
B.Print 20
C.Print 1
D.Compile error
Answer: Option D
Explanation:There is an error in this line i>=45 ? return(*p): return(*q);. We cannot use return keyword in the terenary operators.
57. What will be the output of the program?
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main()
{
printf("%d\n", proc(fun, 6, 6));
return 0;
}
int fun(int a, int b)
{
return (a==b);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
A.6
B.1
C.0
D.-1
Answer: Option B
58. What will be the output of the program?
#include<stdio.h>
int main()
{
int i=1;
if(!i)
printf("IndiaBIX,");
else
{
i=0;
printf("C-Program");
main();
}
return 0;
}
A.prints "IndiaBIX, C-Program" infinitely
B.prints "C-Program" infinetly
C.prints "C-Program, IndiaBIX" infinitely
D.Error: main() should not inside else statement
Answer: Option B
Explanation:Step 1: int i=1; The variable i is declared as an integer type and initialized to 1(one).
Step 2: if(!i) Here the !(NOT) operator reverts the i value 1 to 0. Hence the if(0) condition fails. So it goes to else part.
Step 3: else { i=0; In the else part variable i is assigned to value 0(zero).
Step 4: printf("C-Program"); It prints the "C-program".
Step 5: main(); Here we are calling the main() function.
After calling the function, the program repeats from step 1 to step 5 infinitely.
Hence it prints "C-Program" infinitely.
View Answer C Compiler Report Discuss in Forum
59. What will be the output of the program?
#include<stdio.h>
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d %d\n", k, l);
return 0;
}
A.12 12
B.No error, No output
C.Error: Compile error
D.None of above
Answer: Option A
60.What will be the output of the program?
#include<stdio.h>
int i;
int fun1(int);
int fun2(int);
int main()
{
extern int j;
int i=3;
fun1(i);
printf("%d,", i);
fun2(i);
printf("%d", i);
return 0;
}
int fun1(int j)
{
printf("%d,", ++j);
return 0;
}
int fun2(int i)
{
printf("%d,", ++i);
return 0;
}
int j=1;
A.3, 4, 4, 3
B.4, 3, 4, 3
C.3, 3, 4, 4
D.3, 4, 3, 4
Answer: Option B
Explanation:Step 1: int i; The variable i is declared as an global and integer type.
Step 2: int fun1(int); This prototype tells the compiler that the fun1() accepts the one integer parameter and returns the integer value.
Step 3: int fun2(int); This prototype tells the compiler that the fun2() accepts the one integer parameter and returns the integer value.
Step 4: extern int j; Inside the main function, the extern variable j is declared and defined in another source file.
Step 5: int i=3; The local variable i is defines as an integer type and initialized to 3.
Step 6: fun1(i); The fun1(i) increements the given value of variable i prints it. Here fun1(i) becomes fun1(3) hence it prints '4' then the control is given back to the main function.
Step 7: printf("%d,", i); It prints the value of local variable i. So, it prints '3'.
Step 8: fun2(i); The fun2(i) increements the given value of variable i prints it. Here fun2(i) becomes fun2(3) hence it prints '4' then the control is given back to the main function.
Step 9: printf("%d,", i); It prints the value of local variable i. So, it prints '3'.
Hence the output is "4 3 4 3".
61. What will be the output of the program?
#include<stdio.h>
int func1(int);
int main()
{
int k=35;
k = func1(k=func1(k=func1(k)));
printf("k=%d\n", k);
return 0;
}
int func1(int k)
{
k++;
return k;
}
A.k=35
B.k=36
C.k=37
D.k=38
Answer: Option D
Explanation:Step 1: int k=35; The variable k is declared as an integer type and initialized to 35.
Step 2: k = func1(k=func1(k=func1(k))); The func1(k) increement the value of k by 1 and return it. Here the func1(k) is called 3 times. Hence it increements value of k = 35 to 38. The result is stored in the variable k = 38.
Step 3: printf("k=%d\n", k); It prints the value of variable k "38".
62.What will be the output of the program?
#include<stdio.h>
int addmult(int ii, int jj)
{
int kk, ll;
kk = ii + jj;
ll = ii * jj;
return (kk, ll);
}
int main()
{
int i=3, j=4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d, %d\n", k, l);
return 0;
}
A.12, 12
B.7, 7
C.7, 12
D.12, 7
Answer: Option A
Explanation:Step 1: int i=3, j=4, k, l; The variables i, j, k, l are declared as an integer type and variable i, j are initialized to 3, 4 respectively.
The function addmult(i, j); accept 2 integer parameters.
Step 2: k = addmult(i, j); becomes k = addmult(3, 4)
In the function addmult(). The variable kk, ll are declared as an integer type int kk, ll;
kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'.
ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'.
return (kk, ll); It returns the value of variable ll only.
The value 12 is stored in variable 'k'.
Step 3: l = addmult(i, j); becomes l = addmult(3, 4)
kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'.
ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'.
return (kk, ll); It returns the value of variable ll only.
The value 12 is stored in variable 'l'.
Step 4: printf("%d, %d\n", k, l); It prints the value of k and l
Hence the output is "12, 12".
63. What will be the output of the program?
#include<stdio.h>
int check(int);
int main()
{
int i=45, c;
c = check(i);
printf("%d\n", c);
return 0;
}
int check(int ch)
{
if(ch >= 45)
return 100;
else
return 10;
}
A.100
B.10
C.1
D.0
64. If int is 2 bytes wide.What will be the output of the program?
#include <stdio.h>
void fun(char**);
int main()
{
char *argv[] = {"ab", "cd", "ef", "gh"};
fun(argv);
return 0;
}
void fun(char **p)
{
char *t;
t = (p+= sizeof(int))[-1];
printf("%s\n", t);
}
A.ab
B.cd
C.ef
D.gh
Answer: Option B
Explanation:Since C is a machine dependent language sizeof(int) may return different values.
The output for the above program will be cd in Windows (Turbo C) and gh in Linux (GCC).
To understand it better, compile and execute the above program in Windows (with Turbo C compiler) and in Linux (GCC compiler).
65.What will be the output of the program?
#include<stdio.h>
int fun(int(*)());
int main()
{
fun(main);
printf("Hi\n");
return 0;
}
int fun(int (*p)())
{
printf("Hello ");
return 0;
}
A.Infinite loop
B.Hi
C.Hello Hi D.
Error
Answer: Option C
66. What will be the output of the program?
#include<stdio.h>
int fun(int i)
{
i++;
return i;
}
int main()
{
int fun(int);
int i=3;
fun(i=fun(fun(i)));
printf("%d\n", i);
return 0;
}
A.5
B.4
C.Error
D.Garbage value
Answer: Option A
Explanation:Step 1: int fun(int); This is prototype of function fun(). It tells the compiler that the function fun() accept one integer parameter and returns an integer value.
Step 2: int i=3; The variable i is declared as an integer type and initialized to value 3.
Step 3: fun(i=fun(fun(i)));. The function fun(i) increements the value of i by 1(one) and return it.
Lets go step by step,
=> fun(i) becomes fun(3) is called and it returns 4.
=> i = fun(fun(i)) becomes i = fun(4) is called and it returns 5 and stored in variable i.(i=5)
=> fun(i=fun(fun(i))); becomes fun(5); is called and it return 6 and nowhere the return value is stored.
Step 4: printf("%d\n", i); It prints the value of variable i.(5)
Hence the output is '5'.
67. What will be the output of the program?
#include<stdio.h>
int fun(int);
int main()
{
float k=3;
fun(k=fun(fun(k)));
printf("%f\n", k);
return 0;
}
int fun(int i)
{
i++;
return i;
}
A.5.000000
B.3.000000
C.Garbage value
D.4.000000
Answer: Option A
68. What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i=0;
i++;
if(i<=5)
{
printf("IndiaBIX");
exit(1);
main();
}
return 0;
}
A.Prints "IndiaBIX" 5 times
B.Function main() doesn't calls itself
C.Infinite loop
D.Prints "IndiaBIx"
Answer: Option D
Explanation:Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero).
Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one).
Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements.
Step 4: printf("IndiaBIX"); It prints "IndiaBIX".
Step 5: exit(1); This exit statement terminates the program execution.
Hence the output is "IndiaBIx".
No comments:
Post a Comment