Professional Documents
Culture Documents
Play With C
Play With C
Play With C
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
2. Do logical operators in the C language are evaluated with the short circuit?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
Answer: b
a) Syntax error
b) 1
c) 5
d) 10
View Answer
Answer: b
a) 5 1
b) 0 3
c) 5 3
d) 1 1
View Answer
Answer: a
a) TRUE 1
b) TRUE 2
c) TRUE 1 TRUE 2
d) Compiler Dependent
Answer: d
a) 13
b) 14
c) 12
d) 1 6
View Answer
Answer: a
a) 7
b) 6
c) 10
d) 9
View Answer
Answer: b
a) 10
b) 2
c) -2
d) -3
View Answer
Answer: c
a) 9.000000
b) 9
c) 9.0
d) Run time error
Answer: a
a) -2
b) Floating point Exception
c) 1
d) None of the mentioned
Answer: b
15. What is the type of the below assignment expression if x is of type float, y is of type int?
y = x + y;
a) int
b) float
c) there is no type for an assignment expression
d) double
Answer: a
a) 2
b) True
c) 1
d) 0
Answer: a
Answer: d
a) 1 1
b) 1 2
c) 2 1
d) 2 2
Answer: c
a) Addition of a and n
b) Subtraction of a and n
c) Multiplication of a and n
d) Division of a and n
Answer: c
Answer: d
a) 13
b) 14
c) 12
d) 1 6
Answer: a
a) 7
b) 6
c) 10
d) 9
Answer: b
a) 10
b) 2
c) -2
d) -3
Answer: c
Answer: d
a) 9.000000
b) 9
c) 9.0
d) Run time error
Answer: a
a) -2
b) Floating point Exception
c) 1
d) None of the mentioned
Answer: b
Answer: a
Answer: b
30. The correct way to generate numbers between minimum and maximum(inclusive) is
_________________
a) minimum + (rand() % (maximum – minimum));
b) minimum + (rand() % (maximum – minimum + 1));
c) minimum * (rand() % (maximum – minimum))
d) minimum – (rand() % (maximum+minimum));
Answer: b
Answer: d
Answer: b
33. Which of the following snippet will effectively generate random numbers?
a) rand();
b) rand(10);
c) rand(time(NULL));
d) all of the mentioned
Answer: a
34. Which among the following is correct function call for rand() and random()?
a) rand() and random();
b) rand() and random(1);
c) rand(1) and random(1);
d) rand(1) and random();
Answer: a
35. For the function call time(), what type of parameter is accepted?
a) int
b) int *
c) time_t
d) time_t *
Answer: d
Answer: a
Answer: b
a) 10
b) 11
c) Compile time error
d) 0
Answer: c
a) Yes
b) No
c) Depends on the C standard implemented by compilers
d) None of the mentioned
Answer: c
39)/*Program Snippet 1 with for loop*/
(A) All the loops are equivalent i.e. any of the three can be chosen and they all will perform
exactly same.
(B) continue can’t be used with all the three loops in C.
(C) After hitting the continue; statement in all the loops, the next expression to be executed
would be controlling expression (i.e. i < 10) in all the 3 loops.
(D) None of the above is correct.
Answer: (D)
40) In the context of “break” and “continue” statements in C, pick the best statement.
(A) “break” can be used in “for”, “while” and “do-while” loop body.
(B) “continue” can be used in “for”, “while” and “do-while” loop body.
(C) “break” and “continue” can be used in “for”, “while”, “do-while” loop body and
“switch” body.
(D) “break” and “continue” can be used in “for”, “while” and “do-while” loop body. But
only “break” can be used in “switch” body.
(E) “break” and “continue” can be used in “for”, “while” and “do-while” loop body. Besides,
“continue” and “break” can be used in “switch” and “if-else” body.
Answer: (D)
#include "stdio.h"
int main()
{
int i;
goto LOOP;
for (i = 0 ; i < 10 ; i++)
{
printf("GeeksQuiz\n");
LOOP:
break;
}
return 0;
}
(A) No compile error and it will print GeeksQuiz 10 times because goto label LOOP wouldn’t
come in effect.
(B) No compile error and it’ll print GeeksQuiz only once because goto label LOOP would come
in picture only after entering for loop.
(C) Compile Error because any goto label isn’t allowed in for loop in C.
(D) No compile error but behaviour of the program would depend on C compiler due to
nondeterministic behaviour of goto statement.
(E) No compile error and it will not print anything.
Answer: (E)
switch (controlling_expression)
{
case label1:
/*label1 statements*/
break;
case label2:
/*label1 statements*/
break;
default:
/*Default statements*/
}
Answer: (C)
42)Which of the following is correct with respect to “Jump Statements” in C?
(A) goto
(B) continue
(C) break
(D) return
(E) All of the above.
Answer: (E)
43)Assuming int size is 4 bytes, what is going to happen when we compile and run the
following program?
#include “stdio.h”
int main()
{
printf(“GeeksQuiz\n”);
main();
return 0;
}
(A) We can’t use main() inside main() and compiler will catch it by showing compiler error.
(B) GeeksQuiz would be printed in 2147483647 times i.e. (2 to the power 31) – 1.
(C) It’ll print GeeksQuiz infinite times i.e. the program will continue to run forever until it’s
terminated by other means such as CTRL+C or CTRL+Z etc.
(D) GeeksQuiz would be printed only once. Because when main() is used inside main(), it’s
ignored by compiler at run time. This is to make sure that main() is called only once.
(E) GeeksQuiz would be printed until stack overflow happens for this program.
Answer: (E)
int (*p)[5];
(A) It will result in compile error because there shouldn’t be any parenthesis i.e. “int *p[5]” is
valid.
(B) p is a pointer to 5 integers.
(C) p is a pointer to integer array.
(D) p is an array of 5 pointers to integers.
(E) p is a pointer to an array of 5 integers
Answer: (E)
float x = 2.17;
double y = 2.17;
long double z = 2.17;
Which of the following is correct way for printing these variables via printf.
(A) printf(“%f %lf %Lf”,x,y,z);
(B) printf(“%f %f %f”,x,y,z);
(C) printf(“%f %ff %fff”,x,y,z);
(D) printf(“%f %lf %llf”,x,y,z);
Answer: (A)
A - _
B - _ _
D - =
48) - Which is the storage specifier used to modify the member variable even though the class
object is a constant object?
A - auto
B - register
C - static
D – mutable
#include<iostream>
class Base {
public:
cout<<"Base\n";
};
public:
void f() {
cout<<"Derived\n";
};
main() {
A - Base
B - Derived
50)- Which operator is used to resolve the scope of the global variable?
A - −>
B - .
C - *
D - ::
52) - An exception is __
A - 2
B - 4
C - 8
A - $
B - @
C - _
D - .
#include<iostream>
void main() {
char *s = "C++";
cout<<s<<" ";
s++;
cout<<s<<" ";
C - ++ ++
56) constructor that accepts __________ parameters is called the default constructor.
A
one
.
B. two
C
no
.
D
three
.
Answer: Option C
57)What happens when a class with parameterized constructors and having no default
constructor is used in a program and we create an object that needs a zero-argument
constructor?
A
Compile-time error.
.
B. Preprocessing error.
C
Runtime error.
.
D
Runtime exception.
.
Answer: Option A
B. No
Answer: Option A
59) Destructor has the same name as the constructor and it is preceded by ______ .
A !
.
B. ?
C
~
.
D
$
.
Answer: Option C
60) For automatic objects, constructors and destructors are called each time the objects
A
enter and leave scope
.
C
are constructed
.
D
are destroyed
.
Answer: Option A
61) Which constructor function is designed to copy objects of the same class type?
A
Create constructor
.
B. Object constructor
C
Dynamic constructor
.
D
Copy constructor
.
Answer: Option D
Destructor has the same name as that of the class with a tilde symbol at the
B.
beginning.
C
Both A and B.
.
D
Destructor has the same name as the first member function of the class.
.
Answer: Option C
C
It is necessary that a constructor in a class should always be public.
.
D
Both B and C.
.
Answer: Option D
C
When the control comes out of the function in which they are being used.
.
D
As soon as local objects die.
.
Answer: Option B
B. only pass-by-value
C
only pass-by-reference
.
D
only pass by address
.
Answer: Option C
C
Both A and B.
.
D
float = Show(int, float) Function(Tmp);
.
Answer: Option A
B. We cannot change the argument of the function that that are declared as constant.
C
Both A and B.
.
D
We cannot use the constant while defining the function.
.
Answer: Option C
C
All arguments of an overloaded function can be default.
.
D
A function if overloaded more than once cannot have default argument.
.
Answer: Option C
C Overloaded function must have default arguments starting from the left of
. argument list.
D
A function can be overloaded more than once.
.
Answer: Option D
70) Which of the following statement will be correct if the function has three arguments
passed to it?
A
The trailing argument will be the default argument.
.
C
The middle argument will be the default argument.
.
D
All the argument will be the default argument.
.
Answer: Option A
71) Which of the following statement is incorrect?
A
Default arguments can be provided for pointers to functions.
.
C
Default argument cannot be provided for pointers to functions.
.
D
A default argument cannot be redefined in later declaration.
.
Answer: Option C
C
Constructors cannot have more than one default parameter.
.
D
Constructors can have at most five default parameters.
.
Answer: Option A
B. Static function
C
Virtual function
.
D
Both B and C
.
Answer: Option C
C
int Sum(int a = 0, int b, int c = 3);
.
D
Both B and C are incorrect.
.
C
Compiler uses the prototype information to build a call, not the function definition.
.
D The default arguments are given in the function prototype and should be repeated in
. the function definition.
Answer: Option D
76) What happens when we try to compile the class definition in following code snippet?
class Birds {};
class Peacock : protected Birds {};
A
It will not compile because class body of Birds is not defined.
.
C
It will not compile because a class cannot be protectedly inherited from other class.
.
D
It will compile succesfully.
.
Answer: Option D
B. Friend keyword can be used for a function in the public section of a class.
C
Friend keyword can be used for a function in the private section of a class.
.
D
Friend keyword can be used on main().
.
Answer: Option D
78) Which of the following statement is correct regarding destructor of base class?
A
Destructor of base class should always be static.
.
C
Destructor of base class should not be virtual.
.
D
Destructor of base class should always be private.
.
Answer: Option B
79) Which of the following two entities (reading from Left to Right) can be connected by the dot
operator?
A
A class member and a class object.
.
C
A class and a member of that class.
.
D
A class object and a member of that class.
.
Answer: Option D
C
By declaring it abstract using the static keyword.
.
D
By declaring it abstract using the virtual keyword.
.
Answer: Option B
81) Which of the following statements is correct when a class is inherited publicly?
A
Public members of the base class become protected members of derived class.
.
B. Public members of the base class become private members of derived class.
C
Private members of the base class become protected members of derived class.
.
D
Public members of the base class become public members of derived class.
.
Answer: Option D
82) Which of the following statements is correct about the constructors and destructors?
A
Destructors can take arguments but constructors cannot.
.
C
Destructors can be overloaded but constructors cannot be overloaded.
.
D
Constructors and destructors can both return a value.
.
Answer: Option B
83) Which of the following access specifies is used in a class definition by default?
A
Protected
.
B. Public
C
Private
.
D
Friend
.
Answer: Option C
84) Which of the following statement is correct with respect to the use of friend keyword
inside a class?
A
A private data member can be declared as a friend.
.
C
An object may be declared as a friend.
.
D
We can use friend keyword as a class name.
.
Answer: Option B
B. Break
C
Protected
.
D
Asm
.
Answer: Option C
B. Public members of the base class become private members of derived class.
C
Private members of the base class become protected members of derived class.
.
D
Public members of the base class become public members of derived class.
.
Answer: Option D
87) Which of the following statements is correct about the constructors and destructors?
A
Destructors can take arguments but constructors cannot.
.
C
Destructors can be overloaded but constructors cannot be overloaded.
.
D
Constructors and destructors can both return a value.
.
Answer: Option B
88) Which of the following access specifies is used in a class definition by default?
A
Protected
.
B. Public
C
Private
.
D
Friend
.
Answer: Option C
89) Which of the following statement is correct with respect to the use of friend keyword
. inside a class?
A
A private data member can be declared as a friend.
.
C
An object may be declared as a friend.
.
D
We can use friend keyword as a class name.
.
Answer: Option B
90) Which of the following keywords is used to control access to a class member?
A
Default
.
B. Break
C
Protected
.
D
Asm
.
Answer: Option C
A
all thrown objects
.
C
any thrown object that has not been caught by an earlier catch block
.
D
all thrown objects that have been caught by an earlier catch block
.
A
the bitwise OR operator (|)
.
D
the logical AND operator (&&)
.
Answer: A
A
optional
.
B.compulsory
C
not allowed. It gives an error message
.
D
to check an error
.
Answer: A
94) To expose a data member to the program, you must declare the data member in the _____
section of the class
A. common B. exposed
C. public D. unrestricted
Answer: C
95). Which of the following are valid characters for a numeric literal constant?
A
a comma
.
C
a percent sign (%)
.
D
None of the above
.
Answer: D
96). A function that changes the state of the cout object is called a(n) _____
A. member B. adjuster
C. manipulator D. operator
Answer: C
97) A C++ program contains a function with the header int function(double d, char c). Which of
the following function headers could be used within the same program?
A
char function(double d, char c)
.
D
neither (a) nor (b)
.
Answer: B
98) When the compiler cannot differentiate between two overloaded constructors, they are called
A. overloaded B. destructed
C. ambiguous D. dubious
Answer: C
99) If you design a class that needs special initialization tasks, you will want to design a(n)
_____
A
housekeeping routine
.
B.initializer
C
constructor
.
D
compiler
.
Answer: C
100) Which type of statement does not occur in computer programs?
A. sequence B. loop
C. denial D. selection
Answer: C
101)#include<iostream>
using namespace std;
class A
{
// data members of A
public:
A () { cout << "\n A's constructor"; /* Initialize data members */ }
A (const A &a) { cout << "\n A's Copy constructor"; /* copy data members */}
A& operator= (const A &a) // Assignemt Operator
{
// Handle self-assignment:
if(this == &a) return *this;
class B
{
A a;
// Other members of B
public:
B(A &a) { this->a = a; cout << "\n B's constructor"; }
};
int main()
{
A a1;
B b(a1);
return 0;
}
Answer:
d) A's constructor
A's constructor
B's constructor
A's Assignment Operator
Answer: (D)
103) Which of the following is true about linked list implementation of stack?
(A) In push operation, if new nodes are inserted at the beginning of linked list, then in pop
operation, nodes must be removed from end.
(B) In push operation, if new nodes are inserted at the end, then in pop operation, nodes must be
removed from the beginning.
(C) Both of the above
(D) None of the above
Answer: (D)
Answer: (B)
104) The following postfix expression with single digit operands is evaluated using a stack:
823^/23*+51*-
Note that ^ is the exponentiation operator. The top two elements of the stack after the first * is
evaluated are:
(A) 6, 1
(B) 5, 7
(C) 3, 2
(D) 1, 5
Answer: (A)
105) Assume that the operators +, -, × are left associative and ^ is right associative. The order of
precedence (from highest to lowest) is ^, x , +, -. The postfix expression corresponding to the
infix expression a + b × c – d ^ e ^ f is
(A) abc × + def ^ ^ –
(B) abc × + de ^ f ^ –
(C) ab + c × d – e ^ f ^
(D) – + a × bc ^ ^ def
Answer: (A)
#include<stdio.h>
main()
register int x = 5;
int *p;
p=&x;
x++;
printf("%d",*p);
B - 5
C - 6
A - 2
B - 4
C - 8
#include<stdio.h>
main()
int i = 1;
Charminar:
printf("%d ",i++);
if(i==3) break;
A - 1 2
B - 1 2 3
C - 1 2 4 5
109) - Does both the loops in the following programs prints the correct string length?
#include<stdio.h>
main()
int i;
i=0;
while(s[i++]);
#include<stdio.h>
main()
printf("%d", !0<2);
}
A - 0
B - 1
C - False
D - True
A - stdlib.h
B - memory.h
C - math.h
D - stdio.h
113) - Choose the correct statement that is a combination of these two statements,
#include<stdio.h>
int main()
const int i = 0;
printf("%d\n", i++);
return 0;
A - 100
B - Infinity
C - 0
#include<stdio.h>
int main()
s = str;
while(*s)
printf("%c", *s++);
return 0;
A - Welcome
B - 0
C - Wel
D - Come
#include<stdio.h>
main()
register int x = 5;
int *p;
p=&x;
x++;
printf("%d",*p);
B - 5
C - 6
A - 2
B - 4
C - 8
#include<stdio.h>
main()
int i = 1;
Charminar:
printf("%d ",i++);
if(i==3) break;
A - 1 2
B - 1 2 3
C - 1 2 4 5
119) - Does both the loops in the following programs prints the correct string length?
#include<stdio.h>
main()
int i;
i=0;
while(s[i++]);
#include<stdio.h>
main()
printf("%d", !0<2);
}
A - 0
B - 1
C - False
D - True
#include<stdio.h>
int main()
const int i = 0;
printf("%d\n", i++);
return 0;
A - 100
B - Infinity
C - 0
123) - Return error
1. Which of the following correctly declares an array?
a) int array[10];
b) int array;
c) array{10};
d) array array[10];
2.
1. #include <iostream>
2. #include "exe.h"
3. using namespace std;
4. int main(int argc, char * argv[] )
5. {
6. cout << number++;
7. return 0;
8. }
a)842
b)843
c)compiletimeerror
d) none of the mentioned
130). What is the default type of linkage that is available for identifiers?
a)internal
b)external
c)nolinkage
d) none of the mentioned
131) Which of the following performs deletion of the last element in the list? Given below is the
Node class.
class Node
{
protected Node next;
protected Object ele;
Node(Object e,Node n)
{
ele = e;
next = n;
}
public void setNext(Node n)
{
next = n;
}
public void setEle(Object e)
{
ele = e;
}
public Node getNext()
{
return next;
}
public Object getEle()
{
return ele;
}
}
class SLL
{
Node head;
int size;
SLL()
{
size = 0;
}
}
a)
public Node removeLast()
{
if(size == 0)
return null;
Node cur;
Node temp;
cur = head;
while(cur.getNext() != null)
{
temp = cur;
cur = cur.getNext();
}
temp.setNext(null);
size--;
return cur;
}
b)
public void removeLast()
{
if(size == 0)
return null;
Node cur;
Node temp;
cur = head;
while(cur != null)
{
temp = cur;
cur = cur.getNext();
}
temp.setNext(null);
return cur;
}
c)
public void removeLast()
{
if(size == 0)
return null;
Node cur;
Node temp;
cur = head;
while(cur != null)
{
cur = cur.getNext();
temp = cur;
}
temp.setNext(null);
return cur;
}
d)
public void removeLast()
{
if(size == 0)
return null;
Node cur;
Node temp;
cur = head;
while(cur.getNext() != null)
{
cur = cur.getNext();
temp = cur;
}
temp.setNext(null);
return cur;
}
132). What is the functionality of the following code?
public void function(Node node)
{
if(size == 0)
head = node;
else
{
Node temp,cur;
for(cur = head; (temp = cur.getNext())!=null; cur = temp);
cur.setNext(node);
}
size++;
}
134) How would you delete a node in the singly linked list? The position to be deleted is given.
a)
public void delete(int pos)
{
if(pos < 0)
pos = 0;
if(pos > size)
pos = size;
if( size == 0)
return;
if(pos == 0)
head = head.getNext();
else
{
Node temp = head;
for(int i=1; i<pos; i++)
{
temp = temp.getNext();
}
temp.setNext(temp.getNext().getNext());
}
size--;
}
b)
public void delete(int pos)
{
if(pos < 0)
pos = 0;
if(pos > size)
pos = size;
if( size == 0)
return;
if(pos == 0)
head = head.getNext();
else
{
Node temp = head;
for(int i=1; i<pos; i++)
{
temp = temp.getNext();
}
temp.setNext(temp.getNext());
}
size--;
}
c)
public void delete(int pos)
{
if(pos < 0)
pos = 0;
if(pos > size)
pos = size;
if( size == 0)
return;
if(pos == 0)
head = head.getNext();
else
{
Node temp = head;
for(int i=1; i<pos; i++)
{
temp = temp.getNext().getNext();
}
temp.setNext(temp.getNext().getNext());
}
size--;
}
d)
public void delete(int pos)
{
if(pos < 0)
pos = 0;
if(pos > size)
pos = size;
if( size == 0)
return;
if(pos == 0)
head = head.getNext();
else
{
Node temp = head;
for(int i=0; i<pos; i++)
{
temp = temp.getNext();
}
temp.setNext(temp.getNext().getNext());
}
size--;
}
135) Which of the following piece of code has the functionality of counting the number of
elements in the list?
a)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
size++;
cur = cur.getNext();
}
return size;
}
b)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
cur = cur.getNext();
size++;
}
return size;
}
c)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
size++;
cur = cur.getNext();
}
}
d)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
size++;
cur = cur.getNext().getNext();
}
return size;
}
136) Why do variable names beginning with the underscore is not encouraged?
a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
Answer: c
Answer: c
Explanation: None.
Answer: c
Explanation: None.
Answer: d
Answer: c
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Answer: b.
Answer: b
143) Which of the following statement is false?
a) A variable defined once can be defined again with different scope
b) A single variable cannot be defined with two different types in the same scope
c) A variable must be declared and defined at the same time
d) A variable refers to a location in memory
Answer: c
Answer: a
a) yes
b) yes no
c) Duplicate case value error
d) Character case value error
Answer: c
Answer: a.
Answer: a
148). What is the correct syntax to declare a function foo() which receives an array of structure
in function?
a) void foo(struct *var);
b) void foo(struct *var[]);
c) void foo(struct var);
d) none of the mentioned
Answer: a
a) alan alan
b) Nothing
c) Compile time error
d) Varies
Answer: c
Answer: b
Answer: c
a) myw
b) myworld(note:2 spaces before myworld)
c) myworld (note:2 spaces after myworld)
d) myw(note:6 spaces after myworld)
Answer: d
Answer: b
154)
#include <stdio.h>
int main()
{
printf("\new_c_question\by");
printf("\rgeeksforgeeks");
getchar();
return 0;
}
(A)ew_c_question
geeksforgeeks
(B)new_c_ques
geeksforgeeks
(C)
geeksforgeeks
(D)Dependsonterminalconfiguration
Answer: (D)
155)
#include <stdio.h>
int main()
{
printf(" \"GEEKS %% FOR %% GEEKS\"");
getchar();
return 0;
}
Run on IDE
156)
#include <stdio.h>
int main()
{
printf("%c ", 5["GeeksQuiz"]);
return 0;
}
(A)Compile-timeerror
(B)Runtimeerror
(C)Q
(D)s
Answer: (C)
157)
#include <stdio.h>
int main()
{
printf("%c ", "GeeksQuiz"[5]);
return 0;
}
(A)Compile-timeerror
(B)Runtimeerror
(C)Q
(D)s
Answer:(C)
158)
159)
A) gets() doesn’t do any array bound testing and should not be used.
(B) fgets() should be used in place of gets() only for files, otherwise gets() is fine
(C) gets() cannot read strings with spaces
(D) None of the above
Answer: (A)
160)
#include <stdio.h>
int main(void)
{
int x = printf("GeeksQuiz");
printf("%d", x);
return 0;
}
Run on IDE
(A)GeeksQuiz9
(B)GeeksQuiz10
(C)GeeksQuizGeeksQuiz
(D)GeeksQuiz1
Answer:(A)
161)
What is the return type of getchar()?
(A)int
(B)char
(C)unsignedchar
(D)float
Answer:(A)
162)Normally user programs are prevented from handling I/O directly by I/O instructions in
them. For CPUs having explicit I/O instructions, such I/O protection is ensured by having the I/O
instructions privileged. In a CPU with memory mapped I/O, there is no explicit I/O instruction.
Which one of the following is true for a CPU with memory mapped I/O?
(A) I/O protection is ensured by operating system routine (s)
(B) I/O protection is ensured by a hardware trap
(C) I/O protection is ensured during system configuration
(D) I/O protection is not possible
Answer: (A)
163)
#include "stdio.h"
int main()
{
int a = 10;
int b = 15;
printf("=%d",(a+1),(b=a+2));
printf(" %d=",b);
return 0;
}
(A)=11 15=
(B)=11 12=
(C)Compiler Error due to (b=a+2) in the first printf().
(D) No compile error but output would be =11 X= where X would depend on compiler
implementation.
Answer:(B)
164)
#include "stdio.h"
int foo(int a)
{
printf("%d",a);
return 0;
}
int main()
{
foo;
return 0;
}
Which of the following option is correct?
(A) It’ll result in compile error because foo is used without parentheses.
(B) No compile error and some garbage value would be passed to foo function. This would make
foo to be executed with output “garbage integer”.
(C) No compile error but foo function wouldn’t be executed. The program wouldn’t print
anything.
(D) No compile error and ZERO (i.e. 0) would be passed to foo function. This would make foo
to be executed with output 0.
Answer:(C)
165)
#include <stdio.h>
struct Ournode {
char x, y, z;
};
int main() {
struct Ournode p = {'1', '0', 'a' + 2};
struct Ournode *q = &p;
printf("%c, %c", *((char *)q + 1), *((char *)q + 2));
return 0;
}
The output of this program is:
(A)0,c
(B)0,a+2
(C)‘0’,‘a+2’
(D)‘0’,‘c’
Answer:(A)
Explanation: ‘a’ + 2 will be ‘c’, so Ournode p = {‘1’, ‘0’, ‘c’} and output will be 0, c.
166)
#include <stdio.h>
void fun1(char *s1, char *s2) {
char *temp;
temp = s1;
s1 = s2;
s2 = temp;
}
void fun2(char **s1, char **s2) {
char *temp;
temp = *s1;
*s1 = *s2;
*s2 = temp;
}
int main() {
char *str1 = "Hi", *str2 = "Bye";
fun1(str1, str2);
printf("%s %s", str1, str2);
fun2(&str1, &str2);
printf("%s %s", str1, str2);
return 0;
}
The output of the program above is