C (MCQ+Program)
C (MCQ+Program)
b) 63
c) 12
d) 14
TOPIC 1.1 DATA TYPES, Answer: b
OPERATORS AND Explanation: ISO C99 compiler may
EXPRESSIONS IN C consider only first 63 characters for internal
names.
This section on C interview questions and
2. C99 standard guarantees uniqueness of
answers focuses on “Variable Names”. One
characters for external names.
shall practice these interview questions to
a) 31
improve their C programming skills needed
b) 6
for various interviews (campus interviews,
c) 12
walk-in interviews, company interviews),
d) 14
placements, entrance exams and other
competitive exams. These questions can be Answer: a
attempted by anyone focusing on learning C
Explanation: ISO C99 compiler may
Programming language. They can be a
consider only first 31 characters for external
beginner, fresher, engineering graduate or an
names.
experienced IT professional. Our C Interview
questions come with the detailed explanation 3. Which of the following is not a valid
of the answers which helps in better variable name declaration?
understanding of C concepts. a) int a3;
b) int 3a;
Here is a listing of C interview questions on
c) int A3;
“Variable Names” along with answers,
d) None of the mentioned
explanations and/or solutions:
Answer: d
1. C99 standard guarantees uniqueness of
Explanation: None.
characters for internal names.
4. Which of the following is not a valid
variable name declaration?
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a
Answer: c
Explanation: Variable name cannot start with
a digit.
7. Variable name resolution (number of 2. What will be the output of the following C
significant characters for the uniqueness of code?
variable) depends on
a) Compiler and linker implementations 1. #include <stdio.h>
b) Assemblers and loaders implementations
c) C language 2. int main()
d) None of the mentioned 3. {
1. #include <stdio.h> 3. {
4. int ThisIsVariableName = 12 5. int i;
;
6. for (i = 0; i < 5; i++)
5. int ThisIsVariablename = 14
; 7. if ((char)a[i] == '5')
3. {
3. Which data type is most suitable for storing
a number 65000 in a 32-bit system?
4. int a[5] = {1, 2, 3, 4, 5}; a) signed short
b) unsigned short
c) long a) 128
d) int b) -128
c) Depends on the compiler
Answer: b d) None of the mentioned
Explanation: 65000 comes in the range of
short (16-bit) which occupies the least Answer: b
memory. Signed short ranges from -32768 to Explanation: signed char will be a negative
32767 and hence we should use unsigned number.
short. Output:
$ cc pgm2.c
4. Which of the following is a User-defined $ a.out
data type? -128
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} 7. What will be the output of the following C
Workdays; code?
c) struct {char name[10], int age};
d) all of the mentioned 1. #include <stdio.h>
8. }
a) a
b) Infinite loop
c) Depends on what fgetc returns Output:
d) Depends on the compiler $ cc pgm4.c
$ a.out
Answer: a not equal
Explanation: None.
Output: 2. What will be the output of the following C
$ cc pgm3.c code?
$ a.out
a 1. #include <stdio.h>
Answer: c 6. printf("equal\n");
Explanation: None. 7. else
3. {
Answer: b
Explanation: 0.1 by default is of type double 4. int x = 10000;
which has different representation than float
resulting in inequality even after conversion. 5. double y = 56;
6. int *p = &x; 8. {
int has less bytes than double in any system 4. float x = 'a';
WOW Sanfoundry
Here is a listing of online C test questions on
“Constants” along with answers, explanations b) C programming Class by\n%s Sanfoundry
and/or solutions: c)
1. What will be the output of the following C C programming Class by
code?
%s Sanfoundry
1. #include <stdio.h>
d) Compilation error
2. int main()
Answer: c
3. {
Explanation: This program has only one %s
4. enum {ORANGE = 5, MANGO, BA within first double quotes, so it does not read
NANA = 4, PEACH}; the string “WOW”.
The %s along with the Sanfoundry is not read
5. printf("PEACH = %d\n", PEAC as a format modifier while new line character
H); prints the new line.
Output: results in Compilation error.
$ cc pgm2.c Output:
$ a.out $ cc pgm3.c
C programming Class by pgm3.c: In function ‘main’:
%s Sanfoundry pgm3.c:5: error: expected identifier or ‘(’
before numeric constant
3. In the following code snippet, character
pointer str holds a reference to the string 5. What will be the output of the following C
code?
char *str = "annauniv.edu\0" "training c 1. #include <stdio.h>
lasses";
2. int main()
a) annauniv.edu
b) annauniv.edu\0training classes 3. {
c) annauniv.edutraining classes
d) Invalid declaration 4. int var = 010;
5. printf("%d", var);
Answer: b
Explanation: ‘\0’ is accepted as a char in the 6. }
string. Even though strlen will give length of
string “annauniv.edu”, in memory str is a) 2
pointing to entire string including training b) 8
classes. c) 9
d) 10
4. What will be the output of the following C
code? Answer: b
Explanation: 010 is octal representation of 8.
1. #include <stdio.h> Output:
$ cc pgm4.c
2. #define a 10
$ a.out
3. int main() 8
5. {
Answer: c
Explanation: The #define substitutes a with 6. enum birds m = TIGER;
10 without leaving any identifier, which
7. int k; PARROT will have value 3 + 2.
Output:
8. k = m; $ cc pgm6.c
9. printf("%d\n", k);
$ a.out
5
10. return 0;
8. What will be the output of the following C
11. } code?
a) 0 1. #include <stdio.h>
b) Compile time error
c) 1 2. #include <string.h>
d) 8
3. int main()
Answer: d 4. {
Explanation: m is an integer constant, hence
it is compatible. 5. char *str = "x";
Output:
$ cc pgm5.c 6. char c = 'x';
$ a.out 7. char ary[1];
8
8. ary[0] = c;
7. What will be the output of the following C
code? 9. printf("%d %d", strlen(str)
, strlen(ary));
1. #include <stdio.h>
10. return 0;
2. #define MAX 2
11. }
3. enum bird {SPARROW = MAX + 1, P
ARROT = SPARROW + MAX}; a) 1 1
b) 2 1
4. int main() c) 2 2
d) 1 (undefined value)
5. {
3. {
1. enum types are processed by
a) Compiler 4. printf("sanfoundry\r\nclass
b) Preprocessor \n");
c) Linker
d) Assembler 5. return 0;
Answer: a 6. }
Explanation: None.
a) sanfoundryclass
2. What will be the output of the following C b)
code? sanfoundry
4. printf("sanfoundry\rclass\n Answer: b
"); Explanation: rn combination makes the
cursor move to the next line.
5. return 0; Output:
$ cc pgm9.c
6. }
$ a.out
a) sanfoundryclass sanfoundry
b) class
Answer: c 3. {
Explanation: r is carriage return and moves 4. const int p;
the cursor back. sanfo is replaced by class.
Output: 5. p = 4;
$ cc pgm8.c
$ a.out 6. printf("p is %d", p);
classundry
7. return 0;
8. } pgm11.c:7: error: assignment of read-only
variable ‘p’
a) p is 4 pgm11.c:8: warning: format ‘%d’ expects
b) Compile time error type ‘int’, but argument 2 has type ‘int *
c) Run time error const’
d) p is followed by a garbage value
6. Which of the following statement is false?
Answer: b a) Constant variables need not be defined as
Explanation: Since the constant variable has they are declared and can be defined later
to be declared and defined at the same time, b) Global constant variables are initialized to
not doing it results in an error. zero
Output: c) const keyword is used to define constant
$ cc pgm10.c values
pgm10.c: In function ‘main’: d) You cannot reassign a value to a constant
pgm10.c:5: error: assignment of read-only variable
variable ‘p’
Answer: a
5. What will be the output of the following C Explanation: Since the constant variable has
code? to be declared and defined at the same time,
not doing it results in an error.
1. #include <stdio.h>
7. What will be the output of the following C
2. void main()
code?
3. {
1. #include <stdio.h>
4. int k = 4;
2. void main()
5. int *const p = &k;
3. {
6. int r = 3;
4. int const k = 5;
7. p = &r;
5. k++;
8. printf("%d", p);
6. printf("k is %d", k);
9. }
7. }
a) Address of k
b) Address of r a) k is 6
c) Compile time error b) Error due to const succeeding int
d) Address of k + address of r c) Error, because a constant variable can be
changed only twice
Answer: c d) Error, because a constant variable cannot
Explanation: Since the pointer p is declared be changed
to be constant, trying to assign it with a new
value results in an error. Answer: d
Output: Explanation: Constant variable has to be
$ cc pgm11.c declared and defined at the same time. Trying
pgm11.c: In function ‘main’: to change it results in an error.
Output:
$ cc pgm12.c language. They can be a beginner, fresher,
pgm12.c: In function ‘main’: engineering graduate or an experienced IT
pgm12.c:5: error: increment of read-only professional. Our C Interview questions come
variable ‘k’ with the detailed explanation of the answers
which helps in better understanding of C
8. What will be the output of the following C concepts.
code?
Here is a listing of C interview questions on
1. #include <stdio.h> “Declarations” along with answers,
explanations and/or solutions:
2. int const print()
3. {
1. What will be the output of the following C
code?
4. printf("annauniv.edu");
1. #include <stdio.h>
5. return 0;
2. void foo(const int *);
6. }
3. int main()
7. void main()
4. {
8. {
5. const int i = 10;
9. print();
6. printf("%d ", i);
10. }
7. foo(&i);
a) Error because function name cannot be
8. printf("%d", i);
preceded by const
b) annauniv.edu 9.
c) annauniv.edu is printed infinite times
d) Blank screen, no output 10. }
6. return 0;
2. What will be the output of the following C
code? 7. }
1. #include <stdio.h> a) 10
b) 11
2. int main()
c) Compile time error
3. { d) 0
2. int main() 5. }
3. { a) %f
b) %d
4. int k;
c) %c
5. { d) %s
6. int k; Answer: a
Explanation: %c can be used to print the
7. for (k = 0; k < 10; k++ indexed position.
); %d can still be used to display its ASCII
8. }
value.
%s is recommended.
9. } %f cannot be used for the variable var.
4. int k = 4; Answer: b
Explanation: Since the scope of the variable
5. float k = 4;
declared within a function is restricted only
6. printf("%d", k) within that function, so the above statement is
false.
7. }
7. The name of the variable used in one
a) Compile time error function cannot be used in another function.
b) 4 a) True
b) False
Answer: b Answer: b
Explanation: Since the scope of the variable Explanation: None.
declared within a function is restricted only
within that function, the same name can be 2. What will be the output of the following C
used to declare another variable in another code?
function.
1. #include <stdio.h>
3. {
1. #include <stdio.h>
4. int i = -3;
2. int main()
5. int k = i % 2;
3. {
6. printf("%d\n", k);
4. int i = 5;
7. }
5. i = i / 3;
6. printf("%d\n", i);
a) Compile time error
b) -1 7. return 0;
c) 1
d) Implementation defined 8. }
a) Implementation defined c) 24
b) 1 d) 3
c) 3
d) Compile time error Answer: c
Explanation: None.
Answer: b
Explanation: None. 6. What will be the output of the following C
code?
4. What will be the output of the following C
code? 1. #include <stdio.h>
2. int main() 3. {
3. { 4. int x = 5.3 % 2;
5. } 7. }
a) 3.75 a) Value of x is 1
b) Depends on compiler b) Value of x is 2
c) Value of x is 3
d) Compile time error
Answer: a 3. Which of the following is not an arithmetic
Explanation: None. operation?
a) a * = 10;
Sanfoundry’s 1000+ MCQs on C helps b) a / = 10;
anyone preparing for placement in Infosys c) a ! = 10;
and other companies. Anyone looking for d) a % = 10;
Infosys placement papers should practice
Answer: c
these 1000+ questions continuously for 2-3
Explanation: None.
months, thereby ensuring a top position in
placements. 4. Which of the following data type will
Here is a listing of C test questions on throw an error on modulus operation(%)?
a) char
“Arithmetic Operators” along with answers,
b) short
explanations and/or solutions:
c) int
1. What will be the output of the following C d) float
code?
Answer: d
1. #include <stdio.h> Explanation: None.
2. void main()
This section on C interview questions and
answers focuses on “Relational & Logical 3. {
Operators”. One shall practice these interview
questions to improve their C programming 4. int x = 1, y = 0, z = 5;
skills needed for various interviews (campus
interviews, walkin interviews, company 5. int a = x && y && z++;
interviews), placements, entrance exams and 6. printf("%d", z);
other competitive exams. These questions can
be attempted by anyone focusing on learning 7. }
C Programming language. They can be a
beginner, fresher, engineering graduate or an a) 6
experienced IT professional. Our C Interview b) 5
questions come with detailed explanation of
c) 0 Answer: d
d) Varies Explanation: None.
6. } a) 3
b) 0
a) 3 c) 2
b) 1 d) Run time error
c) Compile time error
d) Run time error Answer: a
Explanation: None.
Answer: c
Explanation: None. 6. What will be the final value of j in the
following C code?
4. What will be the output of the following C
code? 1. #include <stdio.h>
2. void main() 3. {
3. { 4. int i = 0, j = 0;
7. } 8. }
a) -2147483648 a) 0
b) -1 b) 10
c) Run time error c) Depends on the compiler
d) 8 d) Depends on language standard
Answer: a a) Yes
Explanation: None. b) No
c) Depends on the compiler
7. What will be the final value of j in the d) Depends on the standard
following C code?
Answer: b
1. #include <stdio.h> Explanation: None.
2. int main()
Sanfoundry’s 1000+ MCQs on C helps
3. { anyone preparing for placement in IBM and
other companies. Anyone looking for IBM
4. int i = 10, j = 0; placement papers should practice these 1000+
5. if (i || (j = i + 10))
questions continuously for 2-3 months,
thereby ensuring a top position in placements.
6. //do something
Here is a listing of C interview questions on
7. ; “Relational & Logical Operators” along with
answers, explanations and/or solutions:
8. }
1. Are logical operator sequence points?
a) 0 a) True
b) 20 b) False
c) Compile time error c) Depends on the compiler
d) Depends on language standard d) Depends on the standard
Answer: a Answer: a
Explanation: None. Explanation: None.
8. What will be the output of the following C 2. Do logical operators in the C language are
code? evaluated with the short circuit?
a) True
1. #include <stdio.h>
b) False
2. int main() c) Depends on the compiler
d) Depends on the standard
3. {
Answer: a
4. int i = 1; Explanation: None.
5. if (i++ && (i == 1)) 3. What is the result of logical or relational
6. printf("Yes\n");
expression in C?
a) True or False
7. else b) 0 or 1
c) 0 if an expression is false and any positive
8. printf("No\n"); number if an expression is true
d) None of the mentioned
9. }
Answer: b
Explanation: None.
4. What will be the final value of d in the Answer: a
following C code? Explanation: None.
5. int d; Answer: d
Explanation: None.
6. d = b + c == a;
7. What will be the output of the following C
7. printf("%d", d);
code?
8. }
1. #include <stdio.h>
a) Syntax error
2. int main()
b) 1
c) 5 3. {
d) 10
4. int a = 10;
Answer: b
Explanation: None. 5. if (a == a--)
6. printf("TRUE 1\t");
5. What will be the output of the following C
code? 7. a = 10;
3. { 10. }
5. if (x == 0.1) 3. {
6. printf("Sanfoundry"); 4. float x;
7. else 5. int y;
a) 7.000000, 7 a) a
b) Run time error b) b
c) 7.000000, junk c) 97
d) Varies d) Run time error
Answer: c Answer: a
Explanation: None. Explanation: None.
4. What will be the output of the following C 6. When double is converted to float, then the
code? value is?
a) Truncated
1. #include <stdio.h> b) Rounded
c) Depends on the compiler
2. void main()
d) Depends on the standard
3. {
Answer: c
4. double x = 123828749.66; Explanation: None.
Answer: d 6. if (i > c)
10. }
7. return 0;
8. }
a) Yes
b) No a) 2, 1, 2
c) Depends on the compiler b) 2, 1, 1
d) Depends on the standard c) 2, 1, 4
d) 2, 2, 8
Answer: b
Explanation: None. Answer: c
Explanation: None.
Sanfoundry’s 1000+ Interview Questions &
Answers on C helps anyone preparing for 3. Which type of conversion is NOT
Sasken and other companies C interviews. accepted?
One should practice these 1000+ interview a) From char to int
questions and answers continuously for 2-3 b) From float to char pointer
months to clear Sasken interviews on C c) From negative int to char
Programming language. d) From double to char
1. function tolower(c) defined in library 4. What will be the data type of the result of
<ctype.h> works for the following operation?
a) Ascii character set
(float)a * (int)b / (long)c * (double)d
b) Unicode character set
c) Ascii and utf-8 but not EBCDIC character a) int
set
b) long
d) Any character set
c) float language. They can be a beginner, fresher,
d) double engineering graduate or an experienced IT
professional. Our C online test questions
Answer: d come with detailed explanation of the
Explanation: None. answers which helps in better understanding
of C concepts.
5. Which of the following type-casting have
chances for wrap around? Here is a listing of online C test questions on
a) From int to float “Increment and Decrement Operators” along
b) From int to char with answers, explanations and/or solutions:
c) From char to short
d) From char to int 1. What is the difference between the
following 2 codes?
Answer: b
Explanation: None. 1. #include <stdio.h> //Program 1
7. }
7. When do you need to use type-
conversions? 1. #include <stdio.h> //Program 2
a) The value to be stored is beyond the max
limit 2. int main()
b) The value to be stored is in a form not
supported by that data type 3. {
c) To reduce the memory in use, relevant to
4. int d, a = 1, b = 2;
the value
d) All of the mentioned 5. d = a++ +++b;
7. }
This section on online C test focuses on
“Increment and Decrement Operators”. One a) No difference as space doesn’t make any
shall practice these test questions to improve difference, values of a, b, d are same in both
their C programming skills needed for various the case
interviews (campus interviews, walkin b) Space does make a difference, values of a,
interviews, company interviews), placements, b, d are different
entrance exams and other competitive exams. c) Program 1 has syntax error, program 2 is
These questions can be attempted by anyone not
focusing on learning C Programming
d) Program 2 has syntax error, program 1 is Answer: d
not Explanation: None.
7. } 3. {
d) a = 2, b = 2 6. b--;
6. } 2. int main()
a) 15, 4, 5 3. {
b) 9, 6, 9
c) 9, 3, 5 4. int i = 0;
d) Undefined (Compiler Dependent)
5. int j = i++ + i; 6. printf("%d\n", i);
6. printf("%d\n", j); 7. }
7. What will be the output of the following C Sanfoundry’s 1000+ MCQs on C helps
code? anyone preparing for placement in Capgemini
and other companies. Anyone looking for
1. #include <stdio.h> Capgemini placement papers should practice
these 1000+ questions continuously for 2-3
2. int main() months, thereby ensuring a top position in
placements.
3. {
4. int i = 2;
Here is a listing of C questions and puzzles
on “Increment and Decrement Operators”
5. int j = ++i + i; along with answers, explanations and/or
solutions:
6. printf("%d\n", j);
1. What will be the output of the following C
7. }
code?
a) 6 1. #include <stdio.h>
b) 5
c) 4 2. int main()
d) Compile time error
3. {
Answer: a
Explanation: None. 4. int i = 0;
2. int main() 8. }
3. { a) 0, 2
b) 0, 1
4. int i = 2;
c) 1, 2
5. int i = i++ + i; d) Undefined
Answer: a 4. What will be the output of the following C
Explanation: None. code?
6. What will be the output of the following C This section on C interview questions and
code? answers focuses on “Bitwise Operators”. One
1. #include <stdio.h>
shall practice these interview questions to
improve their C programming skills needed
2. void main() for various interviews (campus interviews,
walkin interviews, company interviews),
3. { placements, entrance exams and other
competitive exams. These questions can be
4. int a = 5, b = -7, c = 0, d
attempted by anyone focusing on learning C
;
Programming language. They can be a
5. d = ++a && ++b || ++c; beginner, fresher, engineering graduate or an
experienced IT professional. Our C Interview
6. printf("\n%d%d%d%d", a, b, questions come with detailed explanation of
c, d); the answers which helps in better
7. }
understanding of C concepts.
3. { 3. {
5. a = ~a; 5. if (a >> 1)
7. } 7. }
a) -9 a) 0
b) -10 b) 1
c) -11 c) 2
d) 10 d) No Output
Answer: c Answer: c
Explanation: None. Explanation: None.
3. What will be the output of the following C 5. Comment on the output of the following C
code? code.
3. { 3. {
4. if (7 & 8) 4. int i, n, a = 4;
3. { 3. {
7. } 7. int r = p - k;
a) x is 97 8. printf("%d", r);
b) x is 98
9. }
c) x is 99
d) Run time error a) 4
b) 8
Answer: a
c) 1
Explanation: None.
d) Run time error
7. What will be the output of the following C
Answer: c
code?
Explanation: None.
1. #include <stdio.h>
Sanfoundry’s 1000+ MCQs on C helps
2. void main() anyone preparing for placement in HCL and
3. {
other companies. Anyone looking for HCL
placement papers should practice these 1000+
4. int x = 4, y, z; questions continuously for 2-3 months,
thereby ensuring a top position in placements.
5. y = --x;
Here is a listing of C questions on “Bitwise
6. z = x--; Operators” along with answers, explanations
and/or solutions:
7. printf("%d%d%d", x, y, z);
a) yes 7. else
b) no
8. printf("%d\n", y);
c) compile time error
d) undefined 9.
Answer: b 10. }
Explanation: None.
a) y is 1
6. What will be the output of the following C b) 1
code? c) run time error
d) undefined
1. #include <stdio.h>
Answer: a
2. int main() Explanation: None.
3. {
8. What will be the output of the following C
4. int x = -2; code?
7. else 3. {
8. printf("no\n"); 4. int y = 1;
9. } 5. if (y & (y = 2))
5. if (1 |(y = 1))
This section on C aptitude questions and 2. What will be the output of the following C
answers focuses on “Assignment Operators & code?
Expressions”. One shall practice these
aptitude questions to improve their C 1. #include <stdio.h>
programming skills needed for various
interviews (campus interviews, walkin 2. void main()
9. } a) 6
b) Junk value
a) Its not zero c) Compile time error
b) Its zero d) 7
c) Run time error
d) None Answer: c
Explanation: None.
Answer: a
Explanation: None. 4. What will be the output of the following C
code snippet?
1. #include <stdio.h> 5. x *= x + y;
3. { 7. return 0;
5. } a) 5
b) 6
a) returns 1 c) Undefined behaviour
b) returns 2 d) Compile time error
c) Varies
d) Compile time error Answer: b
Explanation: None.
Answer: d
Explanation: None. 7. What will be the output of the following C
code?
5. What will be the output of the following C
code snippet? 1. #include <stdio.h>
2. void main() 3. {
3. { 4. int x = 2, y = 2;
6. } 7. return 0;
3. { 2. int main()
4. int x = 2, y = 1; 3. {
4. int x = 1, y = 0; a) 2
b) True
5. x &&= y; c) 1
d) 0
6. printf("%d\n", x);
7. } Answer: a
Explanation: None.
a) Compile time error
b) 1 3. Operation “a = a * b + a” can also be
c) 0 written as
d) Undefined behaviour a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
Answer: a c) a = (b + 1)* a;
Explanation: None. d) All of the mentioned
Answer: d
Sanfoundry’s 1000+ Interview Questions & Explanation: None.
Answers on C help anyone preparing for
Microsoft and other companies C interviews. 4. What will be the final value of c in the
One should practice these 1000+ interview following C statement? (Initial value: c = 2)
questions and answers continuously for 2-3
months to clear Microsoft interviews on C 1. c <<= 1;
Programming language.
a) c = 1;
Here is a listing of C test questions on b) c = 2;
“Assignment Operators & Expressions” along c) c = 3;
with answers, explanations and/or solutions: d) c = 4;
1. What is the type of the following Answer: d
assignment expression if x is of type float and Explanation: None.
y is of type int?
5. What will be the output of the following C
y = x + y; code?
a) int 1. #include <stdio.h>
b) float
c) there is no type for an assignment 2. int main()
expression
d) double 3. {
Answer: a 4. int a = 1, b = 2;
Explanation: None. 5. a += b -= a;
7. result += a;
2. int main()
8. }
3. {
4. int x = 2, y = 0;
a) Addition of a and n
b) Subtraction of a and n 5. int z = (y++) ? y == 1 && x
c) Multiplication of a and n : 0;
d) Division of a and n
6. printf("%d\n", z);
Answer: c
7. return 0;
Explanation: None.
8. }
7. Which of the following is an invalid
assignment operator? a) 0
a) a %= 10; b) 1
b) a /= 10; c) Undefined behaviour
c) a |= 10; d) Compile time error
d) None of the mentioned
Answer: a
Answer: d Explanation: None.
Explanation: None.
2. What will be the output of the following C
This section on C interview questions and code?
answers focuses on “Conditional
Expressions”. One shall practice these 1. #include <stdio.h>
interview questions to improve their C 2. int main()
programming skills needed for various
interviews (campus interviews, walkin 3. {
4. int x = 1; Answer: a
Explanation: None.
5. int y = x == 1 ? getchar()
: 2; 4. What will be the output of the following C
6. printf("%d\n", y); code?
7. } 1. #include <stdio.h>
4. int x = 1; Answer: c
Explanation: None.
5. short int i = 2;
5. What will be the output of the following C
6. float f = 3; code?
7. if (sizeof((x == 2) ? f : i
1. #include <stdio.h>
) == sizeof(float))
8. printf("float\n");
2. int main()
9. else if (sizeof((x == 2) ?
3. {
f : i) == sizeof(short int))
4. int y = 1, x = 0;
10. printf("short int\n");
5. int l = (y++, x++) ? y : x;
11. }
6. printf("%d\n", l);
a) float 7. }
b) short int
c) Undefined behaviour a) 1
d) Compile time error b) 2
c) Compile time error
d) Undefined behaviour
Answer: a c) 8
Explanation: None. d) Depends on compiler
8. }
a) returns 1
a) 7 b) returns 2
b) 8 c) Varies
c) Run time error d) Compile time error
d) 15 Answer: d
Answer: a Explanation: None.
Explanation: None.
Sanfoundry’s 1000+ Interview Questions &
7. What will be the output of the following C Answers on C helps anyone preparing for
code? IBM and other companies C interviews. One
should practice these 1000+ interview
1. #include <stdio.h> questions and answers continuously for 2-3
months to clear IBM interviews on C
2. void main()
Programming language.
3. {
Here is a listing of C interview questions on
4. int k = 8; “Conditional Expressions” along with
answers, explanations and/or solutions:
5. int m = 7;
1. What will be the output of the following C
6. int z = k < m ? k = m : m+ code?
+;
8. } 2. void main()
3. {
a) Run time error
b) 7 4. int k = 8;
5. int m = 7; c) a = 2, c = 2;
d) a = 1, c = 2;
6. k < m ? k++ : m = k;
Answer: a
7. printf("%d", k);
Explanation: None.
8. }
4. What will be the data type of the following
a) 7 expression? (Initial data type: a = int, var1 =
b) 8 double, var2 = float)
c) Compile time error
expression (a < 50)? var1 : var2;
d) Run time error
a) int
Answer: c
b) float
Explanation: None.
c) double
d) Cannot be determined
2. What will be the output of the following C
code? Answer: c
1. #include <stdio.h>
Explanation: None.
a) 4. reverse(1);
if (!n)c = b; 5. }
else c = a;
6. void reverse(int i)
b)
7. {
if (n <;= 0)c = b;
else c = a; 8. if (i > 5)
c) 9. exit(0);
Answer: a a) 1 2 3 4 5
Explanation: None. b) 1 2 3 4
c) Compile time error
This section on C language interview d) Stack overflow
questions and answers focuses on
“Precedence and Order of Evaluation”. One Answer: d
shall practice these interview questions to Explanation: None.
improve their C programming skills needed
for various interviews (campus interviews, 2. What will be the output of the following C
walkin interviews, company interviews), function?
placements, entrance exams and other
competitive exams. These questions can be 1. #include <stdio.h>
attempted by anyone focusing on learning C 2. void reverse(int i);
Programming language. They can be a
beginner, fresher, engineering graduate or an 3. int main()
experienced IT professional. Our C language
interview questions come with detailed 4. {
explanation of the answers which helps in
5. reverse(1);
better understanding of C concepts.
6. }
Here is a listing of C language interview
questions “Precedence and Order of 7. void reverse(int i)
Evaluation” along with answers, explanations
and/or solutions: 8. {
2. int main()
12. return reverse((i++, i)); 15. int g()
13. } 16. {
Answer: b a) 0
Explanation: None. b) 1
c) Undefined behaviour
7. What will be the output of the following C d) Compilation error
code?
Answer: b
1. #include <stdio.h> Explanation: None.
2. int main()
9. What will be the output of the following C
3. { code?
2. int main()
3. {
Sanfoundry’s 1000+ Interview Questions &
4. int x = 2, y = 0, l;
Answers on C helps anyone preparing for
5. int z; VMware and other companies C interviews.
One should practice these 1000+ interview
6. z = y = 1, l = x && y; questions and answers continuously for 2-3
months to clear VMware interviews on C
7. printf("%d\n", l); Programming language.
8. return 0;
Here is a listing of online C test questions on
9. } “Precedence and Order of Evaluation” along
with answers, explanations and/or solutions:
a) 0
b) 1 1. What will be the output of the following C
c) Undefined behaviour due to order of code?
evaluation can be different
d) Compilation error 1. #include <stdio.h>
2. int main()
Answer: b
Explanation: None. 3. {
3. {
6. printf("true\n"); 5. int z = x /= y %= 2;
8. printf("false\n"); 7. }
9. } a) 1
b) Compile time error
a) true c) Floating point exception
b) false d) Segmentation fault
c) compile time error
d) undefined behaviour Answer: c
Explanation: None.
Answer: b
Explanation: None. 5. What will be the output of the following C
code?
3. What will be the output of the following C
code? 1. #include <stdio.h>
2. int main() 3. {
3. { 4. int x = 3, y = 2;
6. printf("%d\n", z); 7. }
7. } a) 1
b) 0
a) 0 c) 3
b) 1 d) Compile time error
c) Compile time error
d) Undefined behaviour Answer: a
Explanation: None.
Answer: b
Explanation: None. 6. What will be the output of the following C
code?
4. What will be the output of the following C
code? 1. #include <stdio.h>
2. int main() 3. {
3. { 4. int x = 3; //, y = 2;
5. const int *p = &x; 5. int z = x && y = 1;
7. printf("%d\n", *p); 7. }
8. } a) 0
b) 1
a) Increment of read-only location compile c) Compile time error
error d) 2
b) 4
c) Some garbage value Answer: c
d) Undefined behaviour Explanation: None.
Answer: c 9. What will be the output of the following C
Explanation: None. code?
7. What will be the output of the following C 1. #include <stdio.h>
code?
2. int main()
1. #include <stdio.h>
3. {
2. int main()
4. int x = 0, y = 2;
3. {
5. if (!x && y)
4. int x = 2, y = 2;
6. printf("true\n");
5. int z = x ^ y & 1;
7. else
6. printf("%d\n", z);
8. printf("false\n");
7. }
9. }
a) 1
b) 2 a) True
c) 0 b) False
d) 1 or 2 c) Compile time error
d) Undefined behaviour
Answer: b
Explanation: None. Answer: a
Explanation: None.
8. What will be the output of the following C
code? 10. What will be the output of the following
C code?
1. #include <stdio.h>
1. #include <stdio.h>
2. int main()
2. int main()
3. {
3. {
4. int x = 2, y = 0;
4. int x = 0, y = 2; a) 13
b) 14
5. int z = ~x & y; c) 12
d) 1 6
6. printf("%d\n", z);
7. } Answer: a
Explanation: None.
a) -1
b) 2 2. What will be the output of the following C
c) 0 code?
d) Compile time error
1. #include <stdio.h>
Answer: b
2. void main()
Explanation: None.
3. {
This section on online C test focuses on
4. int a = 2 + 4 + 3 * 5 / 3 -
“Precedence and Order of Evaluation”. One 5;
shall practice these test questions to improve
their C programming skills needed for various 5. printf("%d", a);
interviews (campus interviews, walkin
interviews, company interviews), placements, 6. }
entrance exams and other competitive exams.
These questions can be attempted by anyone a) 7
focusing on learning C Programming b) 6
language. They can be a beginner, fresher, c) 10
engineering graduate or an experienced IT d) 9
professional. Our online C test questions
come with detailed explanation of the Answer: b
answers which helps in better understanding Explanation: None.
of C concepts.
3. What will be the output of the following C
Here is a listing of online C test questions on code?
“Precedence and Order of Evaluation” along
1. #include <stdio.h>
with answers, explanations and/or solutions:
2. void main()
1. What will be the output of the following C
code? 3. {
3. { 6. }
4. int a = 5 * 3 + 2 - 4; a) 10
b) 2
5. printf("%d", a); c) -2
6. }
d) -3
Answer: c Answer: a
Explanation: None. Explanation: None.
4. What will be the output of the following C 6. What will be the output of the following C
code? code?
3. { 3. {
4. int b = 6; 4. double b = 3 % 0 * 1 - 4 /
2;
5. int c = 7;
5. printf("%lf", b);
6. int a = ++b + c--;
6. }
7. printf("%d", a);
a) -2
8. } b) Floating point Exception
c) 1
a) Run time error d) 0
b) 15
c) 13 Answer: b
d) 14 Explanation: None.
Answer: d 7. What will be the output of the following C
Explanation: None. code?
5. What will be the output of the following C 1. #include <stdio.h>
code?
2. void main()
1. #include <stdio.h>
3. {
2. void main(
4. double b = 5 % 3 & 4 + 5 *
3. { 6;
5. b++; 6. }
6. printf("%lf", b); a) 2
b) 30
7. }
c) 2.000000
d) Run time error
a) 9.000000
b) 9 Answer: c
c) 9.0 Explanation: None.
d) Run time error
8. What will be the output of the following C 2. void main()
code?
3. {
1. #include <stdio.h>
4. int k = 0;
2. void main()
5. double b = k++ + ++k + k--;
3. {
6. printf("%d", k);
4. double b = 3 && 5 & 4 % 3;
7. }
5. printf("%lf", b);
a) 6
6. } b) 1
c) 5
a) 3.000000 d) undefined
b) 4.000000
c) 5.000000 Answer: d
d) 1.000000 Explanation: None.
3. { 6. }
a) 5 Answer: b
b) 6 Explanation: None.
c) 3
d) 4 5. What will be the output of the following C
code?
Answer: d
Explanation: None. 1. #include <stdio.h>
3. { 6. printf("%d%d\n", b, h);
4. int b = 5 & 4 | 6; 7. }
5. printf("%d", b);
a) 10 10
6. } b) 10 9
c) 9 10
a) 6 d) 8 10
b) 4
c) 1 Answer: c
d) 0 Explanation: None.
2. void main() 3. {
3. { 4. int a = 2 + 3 - 4 + 8 - 5
% 4;
4. int h = 8;
5. printf("%d\n", a);
5. int b = h++ + h++ + h++;
6. }
6. printf("%d\n", h);
a) 0
7. } b) 8
c) 11
a) 9 d) 9
b) 10
c) 12 Answer: b
d) 11 Explanation: None.
Answer: d 9. What will be the output of the following C
Explanation: None. code?
7. What will be the output of the following C 1. #include <stdio.h>
code?
2. void main()
1. #include <stdio.h>
3. {
2. void main()
4. char a = '0';
3. {
5. char b = 'm';
4. int h = 8;
6. int c = a && b || '1';
5. int b = 4 * 6 + 3 * 4 < 3 ?
4 : 3; 7. printf("%d\n", c);
6. printf("%d\n", b); 8. }
7. } a) 0
b) a
a) 3 c) 1
b) 33 d) m
c) 34
d) Run time error Answer: c
Explanation: None.
Answer: a
Explanation: None. 10. What will be the output of the following
C code?
8. What will be the output of the following C
code? 1. #include <stdio.h>
b = a / b; Answer: a
Explanation: None.
a) Data type should be either of short, int and
long 8. Which function in the following expression
b) Data type should be either of float and will be called first?
double
a = func3(6) - func2(4, 5) / func1(1, 2,
c) All data types are accepted except for (char 3);
*)
d) This code doesn’t swap 2 numbers a) func1();
b) func2();
Answer: b c) func3();
Explanation: None. d) Cannot be predicted
6. What will be the output of the following C Answer: d
code? Explanation: None.
1. #include<stdio.h> 9. Which of the following operator has the
2. int main()
highest precedence in the following?
a) ()
3. { b) sizeof
c) *
4. int a = 1, b = 2, c = 3, d d) +
= 4, e;
Answer: a
5. e = c + d = b * a;
Explanation: None.
6. printf("%d, %d\n", e, d);
10. Which of the following is a ternary
7. } operator?
a) &&
a) 7, 4 b) >>=
b) 7, 2 c) ?:
c) 5, 2 d) ->
d) Syntax error
Answer: c
Answer: d Explanation: None.
Explanation: None.
Sanfoundry’s 1000+ MCQs on C helps
7. Which of the following is the correct order
anyone preparing for placement in Accenture
of evaluation for the given expression?
and other companies. Anyone looking for
a = w % x / y * z; Accenture placement papers should practice
these 1000+ questions continuously for 2-3
a) % / * = months, thereby ensuring a top position in
b) / * % = placements.
Here is a listing of C questions on associativity
“Precedence and Order of Evaluation” along c) Same precedence, different associativity
with answers, explanations and/or solutions: d) All of the mentioned
Answer: c a) 1
Explanation: None. b) 10
c) 20
9. What will be the output of the following C
d) No Output
code?
Answer: a
1. #include <stdio.h>
Explanation: None.
2. int main()
This section on C programming questions and
3. {
answers focuses on “If-then-else Statements”.
4. int a = -1, b = 4, c = 1, d One shall practice these questions to improve
; their C programming skills needed for various
interviews (campus interviews, walkin
5. d = ++a && ++b || ++c; interviews, company interviews), placements,
entrance exams and other competitive exams.
6. printf("%d, %d, %d, %d\n",
a, b, c, d);
These questions can be attempted by anyone
focusing on learning C Programming
7. return 0; language. They can be a beginner, fresher,
engineering graduate or an experienced IT
8. } professional. Our C programming questions
come with detailed explanation of the
a) 0, 4, 2, 1 answers which helps in better understanding
b) 0, 5, 2, 1 of C concepts.
c) -1, 4, 1, 1
d) 0, 5, 1, 0 Here is a listing of C programming questions
on “If-then-else Statements” along with
Answer: a answers, explanations and/or solutions:
Explanation: None.
1. What will be the output of the following C
10. What will be the output of the following code?
C code?
1. #include <stdio.h>
1. #include <stdio.h>
2. void main()
2. int main()
3. {
3. {
4. int x = 5;
4. int p = 10, q = 20, r;
5. if (x < 1)
5. if (r = p = 5 || q > 20)
6. printf("hello");
6. printf("%d", r);
7. if (x == 5)
8. printf("hi"); 3. {
9. else 4. int x = 5;
11. } 6. printf("hello");
a) hi 7. }
b) hello
c) no a) It will display hello
d) error b) It will throw an error
c) Nothing will be displayed
Answer: a d) Compiler dependent
Explanation: None.
Answer: b
2. What will be the output of the following C Explanation: None.
code?
4. What will be the output of the following C
1. #include <stdio.h> code?
4. { 3. {
5. if (x) 4. int x = 0;
6. printf("hi"); 5. if (x == 0)
7. else 6. printf("hi");
a) hi 9. printf("hello");
b) how are you
c) compile time error 10. }
d) error a) hi
Answer: b b) how are you
c) hello
Explanation: None.
d) hihello
3. What will be the output of the following C
Answer: d
code?
Explanation: None.
1. #include <stdio.h>
5. What will be the output of the following C
2. void main() code?
1. #include <stdio.h> 13. printf("2");
3. { 15. }
4. int x = 5; 16. }
8. } Answer: a
Explanation: None.
a) Nothing
b) Run time error 7. What will be the output of the following C
c) Hello code? (Assuming that we have entered the
d) Varies value 1 in the standard input)
7. switch (ch)
1. #include <stdio.h>
8. {
2. void main()
9. case 1:
3. {
10. printf("1\n");
4. int ch;
11. break;
5. printf("enter a value betwe
en 1 to 2:"); 12. printf("Hi");
6. scanf("%d", &ch); 13. default:
9. case 1: 16. }
10. printf("1\n");
a) 1
11. default: b) Hi 2
c) Run time error
12. printf("2\n"); d) 2
13. } Answer: d
Explanation: None.
14. }
11. break; 9. }
10. else 3. {
8. printf("False"); 3. {
9. } 4. if (printf("%d", printf(
")))
a) True
b) False 5. printf("We are Happy");
6. else if (printf("1")) 7. switch (ch)
8. } 9. case 1:
Answer: b 3. {
Explanation: None.
4. int ch;
8. { 14. printf("2\n");
9. case 1: 15. }
11. default: a) 1
b) hi 2
12. printf("2\n"); c) Run time error
13. }
d) 2
14. } Answer: d
Explanation: None.
5. What will be the output of the following C 4. int a = 1, b = 1;
code? (Assuming that we have entered the
value 1 in the standard input) 5. switch (a)
6. {
1. #include <stdio.h>
2. void main()
7. case a*b:
3. {
8. printf("yes ");
9. case a-b:
4. int ch;
10. printf("no\n");
5. printf("enter a value betwe
en 1 to 2:");
11. break;
6. scanf("%d", &ch);
12. }
7. switch (ch, ch + 1)
13. }
8. {
a) yes
9. case 1: b) no
c) Compile time error
10. printf("1\n"); d) yes no
11. break;
Answer: c
12. case 2: Explanation: None.
6. {
Answer: b
Explanation: None. 7. case 'a':
a) yes a) yes no
b) yes default b) yes
c) Undefined behaviour c) no
d) Compile time error d) Compile time error
Answer: d Answer: d
Explanation: None. Explanation: None.
2. What will be the output of the following C 7. printf("First\n");
code?
8. break;
1. #include <stdio.h>
9. case 2:
2. #define max(a) a
10. printf("Second\n");
3. int main()
11. break;
4. {
12. default:
5. int x = 1;
13. printf("Default\n");
6. switch (x)
14. break;
7. {
15. }
8. case max(2):
16. }
9. printf("yes\n");
a) Do
10. case max(1): b) DoFirst
c) DoSecond
11. printf("no\n"); d) DoDefault
12. break;
Answer: c
13. } Explanation: None.
3. {
Answer: c
Explanation: None. 4. int a = 1;
Answer: d 7. }
Explanation: None.
a) if (ch == ‘a’ && ch == ‘A’) printf(“true”);
6. What will be the output of the following C b)
code?
if (ch == 'a')
1. #include <stdio.h>
if (ch == 'a') printf("true");
2. int main()
c) if (ch == ‘a’ || ch == ‘A’) printf(“true”);
3. { d) none of the mentioned
4. int a = 1; Answer: c
Explanation: None.
5. switch (a)
3. {
2. What will be the correct syntax for running
two variable for loop simultaneously? 4. short i;
a)
5. for (i = 1; i >= 0; i++)
for (i = 0; i < n; i++)
for (j = 0; j < n; j += 5) 6. printf("%d\n", i);
b) 7.
2. void main()
Answer: d
Explanation: None. 3. {
4. int k = 0; 5. for (k = 0.0; k < 3.0; k++)
6. printf("Hello"); 7. }
2. What will be the output of the following C 4. What will be the output of the following C
code? code?
3. { 3. {
4. int k; 4. int i = 0;
7. } 7. printf("After loop\n");
a) Hello 8. }
b) Infinite hello
c) Run time error a) In for loop after loop
d) Nothing b) After loop
c) Compile time error
Answer: d d) Undefined behaviour
Explanation: None.
Answer: a
3. What will be the output of the following C Explanation: None.
code?
5. What will be the output of the following C
1. #include <stdio.h> code?
3. { 2. int main()
4. int i = 0; 3. {
5. for (; ; ;) 4. int i = 0;
8. } 7. printf("After loop\n");
7. }
a) In while loop after loop 5. do {
b) After loop
c) Compile time error 6. i++;
d) Infinite loop 7. printf("In while loop\n
");
Answer: c
Explanation: None. 8. } while (i < 3);
5. while (i < 3) 3. {
6. i++; 4. int i = 0;
8. } 6. {
a) 2 7. printf("H");
b) 3
c) 4 8. }
d) 1 9. }
Answer: c a) H
Explanation: None. b) H is printed infinite times
c) Compile time error
6. What will be the output of the following C
d) Varies
code?
Answer: b
1. #include <stdio.h>
Explanation: None.
2. void main()
8. What will be the output of the following C
3. { code?
4. int i = 2; 1. #include <stdio.h>
5. do 2. void main()
6. { 3. {
7. printf("Hi"); 4. int i = 0;
5. do a) Nothing
b) Run time error
6. { c) Varies
7. printf("Hello");
d) Hello is printed infinite times
9. while (i < 8)
Here is a listing of basic C interview
questions on “While Loops” along with 10. {
answers, explanations and/or solutions:
11. i++;
1. What will be the output of the following C
code? 12. printf("hello\n");
1. #include <stdio.h>
13. }
2. void main()
14. }
3. {
15. }
2. i++; 3. {
3. ————- 4. int i = 0, j = 0;
5. i++; 6. {
a) n, n 8. j++;
b) n, n+1 9. }
c) n+1, n
d) n+1, n+1 10. printf("%d, %d\n", i, j);
Answer: d 11. }
Explanation: None.
a) 5, 5
5. What will be the output of the following C b) 5, 10
code? c) 10, 10
d) Syntax error
1. #include <stdio.h>
Answer: c
2. int main() Explanation: None.
3. { 7. Which loop is most suitable to first
4. int i = 0;
perform the operation and then test the
condition?
5. while (i = 0) a) for loop
b) while loop
6. printf("True\n"); c) do-while loop
d) none of the mentioned
7. printf("False\n");
8. }
Answer: c
Explanation: None.
9. }
This section on C interview questions and
answers focuses on “Break and Continue 10. }
statements”. One shall practice these
interview questions to improve their C a) 2
programming skills needed for various b) 3
interviews (campus interviews, walkin c) 4
interviews, company interviews), placements, d) 5
entrance exams and other competitive exams.
These questions can be attempted by anyone Answer: d
focusing on learning C Programming Explanation: None.
language. They can be a beginner, fresher,
engineering graduate or an experienced IT 3. What will be the output of the following C
professional. Our C Interview questions come code?
with detailed explanation of the answers
which helps in better understanding of C 1. #include <stdio.h>
concepts. 2. int main()
1. Which keyword can be used for coming 5. for (i = 0;i < 5; i++)
out of recursion?
6. {
a) break
b) return 7. a++;
c) exit
d) both break and return 8. if (i == 3)
Answer: b 9. break;
Explanation: None.
10. }
2. What will be the output of the following C 11. }
code?
a) 1
1. #include <stdio.h>
b) 2
2. int main() c) 3
d) 4
3. {
Answer: d
4. int a = 0, i = 0, b; Explanation: None.
5. for (i = 0;i < 5; i++) 4. The keyword ‘break’ cannot be simply
6. {
used within
a) do-while
7. a++; b) if-else
c) for
8. continue; d) while
Answer: b 7. What will be the output of the following C
Explanation: None. code?
Answer: b 5. int j = 0;
Explanation: None.
6. for (i = 0;i < 5; i++)
6. What will be the output of the following C
7. {
code?
8. for (j = 0;j < 4; j++)
1. #include <stdio.h>
9. {
2. void main()
10. if (i > 1)
3. {
11. continue;
4. int i = 0, j = 0;
12. printf("Hi \n")
5. for (i = 0;i < 5; i++) ;
6. { 13. }
8. { 15. }
9. if (i > 1)
a) Hi is printed 9 times
10. break; b) Hi is printed 8 times
c) Hi is printed 7 times
11. } d) Hi is printed 6 times
12. printf("Hi \n"); Answer: b
Explanation: None.
13. }
14. }
8. What will be the output of the following C
code?
a) Hi is printed 5 times
b) Hi is printed 9 times 1. #include <stdio.h>
6. if (i < 4) 9. }
7. { 10. }
11. } Answer: d
Explanation: None.
a) Hello is printed 5 times
b) Hello is printed 4 times 2. What will be the output of the following C
c) Hello code?
d) Hello is printed 3 times
1. #include <stdio.h>
Answer: c
Explanation: None. 2. void main()
3. {
Sanfoundry’s 1000+ MCQs on C helps
anyone preparing for placement in Microsoft 4. int i = 0;
and other companies. Anyone looking for 5. if (i == 0)
Microsoft placement papers should practice
these 1000+ questions continuously for 2-3 6. {
months, thereby ensuring a top position in
placements. 7. printf("Hello");
3. { Answer: d
Explanation: None.
4. int i = 0;
3. What will be the output of the following C
5. if (i == 0) code?
6. { 1. #include <stdio.h>
7. printf("Hello"); 2. int main()
3. { 11. printf("2\n");
4. int i = 0; 12. }
6. { 14. }
7. i++; a)
8. if (i == 2) 1
2
9. continue; after loop
3. {
5. What will be the output of the following C
4. int i = 0, j = 0; code?
7. { 3. {
8. printf("1\n"); 4. int i = 0;
10. } 6. {
7. if (i == 1) 7. {
8. break; 8. i++;
10. if (i == 1) 10. {
15. } 15. }
a) 16. }
2. int main()
6. What will be the output of the following C
code? 3. {
3. { 6. printf("after continue\n");
4. int i = 0; 7. }
6. {
4. What will be the output of the following C
code? 7. i++;
2. int main() 9. {
3. { 10. printf("loop\n");
6. { 13. }
7. l1 : i++; 14. }
12. } 3. {
13. } 4. int i = 0, k;
14. } 5. if (i == 0)
Answer: a 9. printf("hi\n");
Explanation: None.
10. label: k = printf(
7. What will be the output of the following C "%03d", i);
code?
11. }
1. #include <stdio.h> 12. }
2. void main()
a) 0
3. { b) hi hi hi 0 0 0
c) 0 hi hi hi 0 0 0
4. int i = 0; d) 0 0 0
5. if (i == 0) Answer: a
Explanation: None.
6. {
9. {
5. What will be the output of the following C
code? 10. printf("loop\n");
3. { 13. }
6. { 13. }
7. i++; 14. }
13. }
14. }
UNIT II ARRAYS AND
a) loop loop
b) Compile time error STRINGS & UNIT III
c) loop loop loop loop FUNCTIONS AND
d) Infinite loop
POINTERS
Answer: b
Explanation: None.
TOPIC 2.1 STRING
8. What will be the output of the following C OPERATIONS IN C
code?
1. There are two groups of string functions
1. #include <stdio.h> defined in the header <string.h>. What are
they?
2. int main()
a) first group names beginning with str;
3. { second group names beginning with mem
b) first group names beginning with str;
4. int i = 0, j = 0; second group names beginning with is
c) first group names beginning with string;
5. l1: while (i < 2)
second group names beginning with mem
6. {
d) first group names beginning with str;
second group names beginning with type
7. i++;
Answer: a
8. while (j < 3) Explanation: There are two groups of string
functions declared under the header
9. { <string.h>. The first have names beginning
10. printf("loop\n"
with str and second have names beginning
); with mem.
7. Which of the following is the variable type 10. What will be the output of the following
defined in header string. h? C code?
a) sizet
const char str1[]="ABCDEF1234567";
b) size const char str2[] = "269";
c) size_t len = strcspn(str1, str2);
d) size-t printf("First matching character is at %d
\n", len + 1);
Answer: c
Explanation: This is the unsigned integral a) First matching character is at 8
type and is the result of the sizeof keyword. b) First matching character is at 7
c) First matching character is at 9
8. NULL is the macro defined in the header d) First matching character is at 12
string. h.
a) true Answer: a
b) false Explanation: size_t strcspn(const char *str1,
const char *str2) is used to calculate the
Answer: a length of the initial segment of str1, which
Explanation: NULL macro is the value of a consists entirely of characters not in str2.
null pointer constant.
9. What will be the output of the following C 1. What is the return value of strxfrm()?
code? a) length of the transformed string, not
including the terminating null-character
const char pla[] = "string1"; b) length of the transformed string, including
const char src[] = "string2"; the terminating null-character
printf("Before memmove place= %s, src = % c) display the transformed string, not
s\n", pla, src);
memmove(pla, src, 7);
including the terminating null character
d) display the transformed string, not 5. which of the following function returns a
including the terminating null-character pointer to the located string or a null pointer
if string is not found.
Answer: a a) strtok()
Explanation: This function returns the length b) strstr()
of the transformed string, not including the c) strspn()
terminating null character. d) strrchr()
2. Is there any function declared as strstr()? Answer: b
a) true Explanation: The strstr() function is used to
b) false return a pointer to the located string, or if
string is not found a null pointer is returned.
Answer: a
Explanation: This function returns a pointer 6. Which of the given function is used to
to the first occurrence in s1 of any of the return a pointer to the located character?
entire sequence of characters specified in s2, a) strrchr()
or a null pointer if the sequence is not present b) strxfrm()
in s1. c) memchar()
char *strstr(const char *s1, const char *s2) d) strchar()
Answer: a 3. {
Explanation: None.
4. void foo();
2. What will be the output of the following C 5. void f()
code?
6. {
1. #include <stdio.h>
7. foo();
2. int main()
8. }
3. {
9. f();
4. void foo(), f();
10. }
5. f();
11. void foo()
6. }
12. {
7. void foo()
13. printf("2 ");
8. {
14. }
9. printf("2 ");
a) 2 2
10. }
b) 2
c) Compile time error 3. int main()
d) Depends on the compiler
4. {
Answer: d
5. void foo(int);
Explanation: Even though the answer is 2,
this code will compile fine only with gcc. 6. foo(1);
GNU C supports nesting of functions in C as
a language extension whereas standard C 7. return 0;
compiler doesn’t.
8. }
4. What will be the output of the following C
9. void foo(int i)
code?
10. {
1. #include <stdio.h>
11. printf("2 ");
2. void foo();
12. }
3. int main()
a) 2
4. {
b) Compile time error
5. void foo(); c) Depends on the compiler
d) Depends on the standard
6. foo();
Answer: a
7. return 0; Explanation: None.
8. }
6. What will be the output of the following C
9. void foo() code?
Answer: b 7. return 0;
Explanation: None.
8. }
5. What will be the output of the following C
9. void foo()
code?
10. {
1. #include <stdio.h>
11. printf("2 ");
2. void foo();
12. } 6. }
a) 2 7. void main()
b) Compile time error
c) Depends on the compiler 8. {
Answer: b 10. {
Explanation: None.
11. printf("hi");
7. What will be the output of the following C
code? 12. }
13. }
1. #include <stdio.h>
2. void m() a) hi
b) Compile time error
3. { c) Nothing
d) Varies
4. printf("hi");
Answer: b
5. }
Explanation: None.
6. void main()
This section on C interview questions and
7. { answers focuses on “Basics of Functions”.
8. m();
One shall practice these interview questions
to improve their C programming skills needed
9. } for various interviews (campus interviews,
walkin interviews, company interviews),
a) hi placements, entrance exams and other
b) Run time error competitive exams. These questions can be
c) Nothing attempted by anyone focusing on learning C
d) Varies Programming language. They can be a
beginner, fresher, engineering graduate or an
Answer: a experienced IT professional. Our C Interview
Explanation: None. questions come with detailed explanation of
the answers which helps in better
8. What will be the output of the following C understanding of C concepts.
code?
Here is a listing of C interview questions on
1. #include <stdio.h> “Basics of Functions” along with answers,
explanations and/or solutions:
2. void m();
9. main();
Answer: b
Explanation: None. 10. }
Answer: c 7. int x;
Explanation: None.
8. void m()
8. The value obtained in the function is given
back to main by using keyword. 9. {
a) return 10. x = 4;
b) static
c) new 11. }
d) volatile
a) 4
Answer: a b) Compile time error
Explanation: None. c) 0
d) Undefined
Answer: b a) Run time error
Explanation: None. b) 3 3
c) 3 5
2. What will be the output of the following C d) 3 4
code?
Answer: d
1. #include <stdio.h> Explanation: None.
2. int x; 4. What will be the output of the following C
3. void main()
code?
4. { 1. #include <stdio.h>
6. } 3. void main()
a) Junk value 4. {
Answer: c 7. {
Explanation: None.
8. int x = 4;
3. What will be the output of the following C 9. }
code?
10. printf("%d", x);
1. #include <stdio.h>
11. }
2. int x = 5;
a) 3 3
3. void main()
b) 3 4
4. { c) 3 5
d) Run time error
5. int x = 3;
Answer: a
6. printf("%d", x); Explanation: None.
7. { 5. Functions in C are always
8. x = 4;
a) Internal
b) External
9. } c) Both Internal and External
d) External and Internal are not valid terms
10. printf("%d", x); for functions
11. } Answer: b
Explanation: None.
6. Global variables are 4. printf("%d", d++);
a) Internal
b) External 5. }
c) Both Internal and External
6. int d = 10;
d) None of the mentioned
a) 9
Answer: b
b) 10
Explanation: None. c) 11
d) Compile time error
7. Which of the following is an external
variable in the following C code? Answer: d
Explanation: None.
1. #include <stdio.h>
3. {
Here is a listing of basic C interview Answer: b
questions on “External Variable” along with Explanation: None.
answers, explanations and/or solutions:
3. Which part of the program address space is
1. What will be the output of the following C p stored in the following C code?
code?
1. #include <stdio.h>
1. #include <stdio.h>
2. int *p;
2. double i;
3. int main()
3. int main()
4. {
4. {
5. int i = 0;
5. printf("%g\n",i);
6. p = &i;
6. return 0;
7. return 0;
7. }
8. }
a) 0
b) 0.000000 a) Code/text segment
c) Garbage value b) Data segment
d) Depends on the compiler c) Bss segment
d) Stack
Answer: a
Explanation: None. Answer: c
Explanation: None.
2. Which part of the program address space is
p stored in the following C code? 4. Can variable i be accessed by functions in
another source file?
1. #include <stdio.h>
1. #include <stdio.h>
2. int *p = NULL;
2. int i;
3. int main()
3. int main()
4. {
4. {
5. int i = 0;
5. printf("%d\n", i);
6. p = &i;
6. }
7. return 0;
a) Yes
8. } b) No
c) Only if static keyword is used
a) Code/text segment d) Depends on the type of the variable
b) Data segment
c) Bss segment Answer: a
d) Stack Explanation: None.
5. Property of the external variable to be 7. return 0;
accessed by any source file is called by the
C90 standard as 8. }
a) external linkage
b) external scope a) true
c) global scope b) true only if NULL value is 0
d) global linkage c) Compile time error
d) Nothing
Answer: a
Explanation: None. Answer: b
Explanation: None.
6. What will be the output of the following C
code? 8. What will be the output of the following C
code?
1. #include <stdio.h>
1. #include <stdio.h>
2. int *i;
2. static int x = 5;
3. int main()
3. void main()
4. {
4. {
5. if (i == NULL)
5. x = 9;
6. printf("true\n");
6. {
7. return 0;
7. int x = 4;
8. }
8. }
a) true
9. printf("%d", x);
b) true only if NULL value is 0
c) Compile time error 10. }
d) Nothing
a) 9
Answer: a b) 4
Explanation: None. c) 5
d) 0
7. What will be the output of the following C
code? Answer: a
Explanation: None.
1. #include <stdio.h>
8. } 5. printf("%d\n", ary1[0]);
a) scope rules 6. }
b) Compile time error due to multiple
declaration a) Value of ary1[0];
c) Compile time error due to not defining type b) Compile time error due to multiple
in statement extern i definition
d) Nothing will be printed as value of i is not c) Compile time error because size of array is
zero because i is an automatic variable not provided
d) Compile time error because datatype of
Answer: a array is not provided
Explanation: None.
Answer: d
2. What will be the output of the following C Explanation: None.
code (without linking the source file in which
ary1 is defined)? 4. What is the scope of an external variable?
a) Whole source file in which it is defined
1. #include <stdio.h> b) From the point of declaration to the end of
the file in which it is defined
2. int main() c) Any source file in a program
d) From the point of declaration to the end of 3. int main()
the file being compiled
4. {
Answer: d
5. int c;
Explanation: None.
6. return 0;
5. What is the scope of a function?
a) Whole source file in which it is defined 7. }
b) From the point of declaration to the end of
the file in which it is defined 8. int a;
c) Any source file in a program
d) From the point of declaration to the end of a) a
the file being compiled b) b
c) c
Answer: d d) Both a and b
Explanation: None.
Answer: b
6. Comment on the output of the following C Explanation: None.
code.
8. Comment on the following 2 C programs.
1. #include <stdio.h>
1. #include <stdio.h> //Program 1
2. int main()
2. int main()
3. {
3. {
4. int i;
4. int a;
5. for (i = 0;i < 5; i++)
5. int b;
6. int a = i;
6. int c;
7. printf("%d", a);
7. }
8. }
8.
a) a is out of scope when printf is called
9. #include <stdio.h> //Program 2
b) Redeclaration of a in same scope throws
error 10. int main()
c) Syntax error in declaration of a
d) No errors, program will show the output 5 11. {
18. } 6. int b;
19. } 7. }
1. #include <stdio.h> 9. }
2. int main() a) 4
b) 3
3. {
c) 0
4. int a; d) Undefined
Answer: a 2. int x;
Explanation: None.
3. void main()
4. What will be the output of the following C
4. {
code?
5. m();
1. #include <stdio.h>
6. printf("%d", x);
2. int x = 5;
7. }
3. void main()
8. void m()
4. {
9. {
5. int x = 3;
10. x = 4;
6. m();
11. }
7. printf("%d", x);
a) 0
8. }
b) 4
9. void m() c) Compile time error
d) Undefined
10. {
Answer: b
11. x = 8; Explanation: None.
12. n();
6. What will be the output of the following C
13. } code?
17. } 4. {
a) 8 3 5. int x = 9;
b) 3 8 6. {
c) 8 5
d) 5 3 7. x = 4;
Answer: a 8. }
Explanation: None.
9. printf("%d", x);
5. What will be the output of the following C
10. }
code?
a) 9
1. #include <stdio.h>
b) 5
c) 4 3. {
d) 0
4. m();
Answer: c
Explanation: None. 5. m();
6. }
7. What will be the output of the following C
code? 7. void m()
1. #include <stdio.h> 8. {
3. { 10. x++;
5. int x = 8; 12. }
6. } a) 6 7
b) 6 6
7. printf("%d", x);
c) 5 5
8. } d) 5 6
a) 8 Answer: a
b) 0 Explanation: None.
c) Undefined
d) Compile time error 2. What will be the output of the following C
code?
Answer: d
Explanation: None. 1. #include <stdio.h>
2. void main()
Sanfoundry’s 1000+ MCQs on C helps
anyone preparing for placement in Oracle and 3. {
other companies. Anyone looking for Oracle 4. static int x;
placement papers should practice these 1000+
questions continuously for 2-3 months, 5. printf("x is %d", x);
thereby ensuring a top position in placements.
6. }
Here is a listing of C questions and puzzles
on “Static Variables” along with answers, a) 0
explanations and/or solutions: b) 1
c) Junk value
1. What will be the output of the following C d) Run time error
code?
Answer: a
1. #include <stdio.h> Explanation: None.
2. void main()
3. What will be the output of the following C 1. #include <stdio.h>
code?
2. void main()
1. #include <stdio.h>
3. {
2. static int x;
4. static int x;
3. void main()
5. if (x++ < 2)
4. {
6. main();
5. int x;
7. }
6. printf("x is %d", x);
a) Infinite calls to main
7. } b) Run time error
c) Varies
a) 0 d) main is called twice
b) Junkvalue
c) Run time error Answer: d
d) Nothing Explanation: None.
15. { 3. {
17. } 5. foo();
18. 6. }
a) 11 12 11 12 4. {
b) 11 13 11 14
5. static int b = 20;
c) 11 12 11 13
d) Compile time error 6. func();
Answer: b 7. }
Explanation: None.
8. void func()
5. Assignment statements assigning value to
local static variables are executed only once. 9. {
a) True 10. static int b;
b) False
c) Depends on the code 11. printf("%d", b);
d) None of the mentioned
12. }
Answer: b
Explanation: None. a) Output will be 0
b) Output will be 20
6. What is the format identifier for “static a = c) Output will be a garbage value
20.5;”? d) Compile time error due to redeclaration of
a) %s static variable
b) %d
c) %f Answer: a
d) Illegal declaration due to absence of data Explanation: None.
type
This section on C interview questions and
Answer: b answers focuses on “Register Variables”. One
Explanation: None. shall practice these interview questions to
improve their C programming skills needed
7. Which of the following is true for the static for various interviews (campus interviews,
variable? walkin interviews, company interviews),
a) It can be called from another function placements, entrance exams and other
b) It exists even after the function ends competitive exams. These questions can be
c) It can be modified in another function by attempted by anyone focusing on learning C
sending it as a parameter Programming language. They can be a
d) All of the mentioned beginner, fresher, engineering graduate or an
experienced IT professional. Our C Interview
Answer: b questions come with detailed explanation of
Explanation: None. the answers which helps in better
understanding of C concepts.
8. What will be the output of the following C
code?
Here is a listing of C interview questions on 4. register static int i = 10;
“Register Variables” along with answers,
explanations and/or solutions: 5. i = 11;
6. printf("%d\n", i);
1. What will be the output of the following C
code? 7. }
1. #include <stdio.h> a) 10
2. int main()
b) Compile time error
c) Undefined behaviour
3. { d) 11
2. int main() 3. {
6. printf("%d\n", i); 9. {
7. } 10. x++;
a) 10 11. }
b) Compile time error
c) Undefined behaviour a) 6
d) 11 b) 5
c) Junk value
Answer: b d) Compile time error
Explanation: None.
Answer: d
6. Register storage class can be specified to Explanation: None.
global variables.
a) True Sanfoundry’s 1000+ MCQs on C helps
b) False anyone preparing for placement in Samsung
c) Depends on the compiler and other companies. Anyone looking for
d) Depends on the standard Samsung placement papers should practice
these 1000+ questions continuously for 2-3
Answer: b months, thereby ensuring a top position in
Explanation: None. placements.
7. Which among the following is wrong for Here is a listing of C interview questions on
“register int a;”? “Register Variables” along with answers,
a) Compiler generally ignores the request explanations and/or solutions:
b) You cannot take the address of this
variable 1. When compiler accepts the request to use
c) Access time to a is critical the variable as a register?
d) None of the mentioned a) It is stored in CPU
b) It is stored in cache memory
Answer: d c) It is stored in main memory
Explanation: None. d) It is stored in secondary memory
8. What will be the output of the following C Answer: a
code? Explanation: None.
1. #include <stdio.h> 2. Which data type can be stored in register?
a) int
2. void main()
b) long
3. { c) float
d) all of the mentioned
4. register int x = 5;
Answer: d
5. m(); Explanation: None.
6. printf("x is %d", x);
3. Which of the following operation is not
7. } possible in a register variable?
a) Reading the value into a register variable a) Segmentation fault
b) Copy the value from a memory variable b) main is called twice
c) Global declaration of register variable c) main is called once
d) All of the mentioned d) main is called thrice
Answer: d Answer: a
Explanation: None. Explanation: None.
4. Which among the following is the correct 7. What will be the output of the following C
syntax to declare a static variable register? code?
a) static register a;
b) register static a; 1. #include <stdio.h>
c) Both static register a; and register static a;
d) We cannot use static and register together 2. void main()
3. {
Answer: d
Explanation: None. 4. register int x;
a) 10 Answer: d
b) Compile time error Explanation: None.
c) Depends on the standard
d) Depends on the compiler 4. What will be the x in the following C
code?
Answer: a
Explanation: None. 1. #include <stdio.h>
2. void main()
Sanfoundry’s 1000+ Interview Questions &
Answers on C helps anyone preparing for 3. {
Samsung and other companies C interviews. 4. int x;
One should practice these 1000+ interview
questions and answers continuously for 2-3 5. }
months to clear Samsung interviews on C
Programming language. a) automatic variable
b) static variable
Here is a listing of online C test questions on c) register variable
“Automatic Variables” along with answers, d) global variable
explanations and/or solutions:
Answer: a Here is a listing of C questions and puzzles
Explanation: None. on “C Preprocessor” along with answers,
explanations and/or solutions:
5. Automatic variables are initialized to
1. Property which allows to produce different
a) Zero executable for different platforms in C is
b) Junk value called?
c) Nothing a) File inclusion
d) Both Zero & Junk value b) Selective inclusion
c) Conditional compilation
Answer: b d) Recursive macros
Explanation: None.
Answer: c
6. Which of the following storage class Explanation: Conditional compilation is the
supports char data type? preprocessor facility to produce a different
a) register executable.
b) static
c) auto 2. What is #include <stdio.h>?
d) all of the mentioned a) Preprocessor directive
b) Inclusion directive
Answer: d c) File inclusion directive
Explanation: None. d) None of the mentioned
7. A local variable declaration with no storage Answer: a
class specified is by default Explanation: None.
a) auto
b) extern 3. C preprocessors can have compiler specific
c) static features.
d) register a) True
b) False
Answer: a c) Depends on the standard
Explanation: None. d) Depends on the platform
Answer: b Answer: b
Explanation: None. Explanation: None.
3. What would happen if you create a file 6. Can function definition be present in
stdio.h and use #include “stdio.h”? header files?
a) The predefined library file will be selected a) Yes
b) The user-defined library file will be b) No
c) Depends on the compiler 10. printf("%d\n", foo(2, 3));
d) Depends on the standard
11. }
Answer: a
Explanation: None. a) 23
b) 2 3
7. Comment on the output of the following C c) Compile time error
code. d) Undefined behaviour
2. int main() 8. }
3. {
a) Compile time error
4. char *p = NULL; b) Segmentation fault/runtime crash
c) 10
5. char *q = 0; d) Undefined behaviour
6. if (p) Answer: a
Explanation: None.
7. printf(" p ");
1. #include <stdio.h>
8. int *f()
2. int *f();
9. {
3. int main()
10. int j = 10;
4. {
11. return &j;
5. int *p = f();
12. }
6. printf("%d\n", *p); a) 10
b) Compile time error
7. } c) Segmentation fault/runtime crash
d) Undefined behaviour
8. int *f()
Answer: a
9. {
Explanation: We are returning address of a
10. int *j = (int*)malloc(sizeo local variable which should not be done. In
f(int)); this specific instance, we are able to see the
value of 10, which may not be the case if we
11. *j = 10; call other functions before calling printf() in
main().
12. return j;
pointed by ptr 4. {
d) You can change the pointer as well as the
value pointed by it 5. int *ptr = &x;
9. { 1. #include <stdio.h>
11. }
3. int main()
4. {
5. int i = 10, *p = &i; c) Compile time error
d) Segmentation fault/code crash
6. foo(&i);
Answer: a
7. }
Explanation: None.
8. void foo(float *p)
5. What will be the output of the following C
9. { code?
a) 10.000000 3. {
b) 0.000000
c) Compile time error 4. int i = 97, *p = &i;
7. } a) 2 2
b) 2 97
8. void foo(int *p) c) Undefined behaviour
d) Segmentation fault/code crash
9. {
Answer: a
10. int j = 2;
Explanation: None.
11. p = &j;
6. What will be the output of the following C
12. printf("%d ", *p); code?
a) 2 97 2. int main()
b) 2 2
3. { 10. void foo(int **const p)
8. } 15. }
2. int main() 8. }
9. } a) 11 11
b) Undefined behaviour
c) Compile time error 3. Arguments that take input by user before
d) Segmentation fault/code-crash running a program are called?
a) Main function arguments
Answer: a b) Main arguments
Explanation: None. c) Command-Line arguments
d) Parameterized arguments
9. Which of the following is the correct
syntax to send an array as a parameter to Answer: c
function? Explanation: None.
a) func(&array);
b) func(#array); 4. What is the maximum number of
c) func(*array); arguments that can be passed in a single
d) func(array[size]); function?
a) 127
Answer: a b) 253
Explanation: None. c) 361
d) No limits in number of arguments
Sanfoundry’s 1000+ Interview Questions &
Answers on C helps anyone preparing for Answer: b
Citrix and other companies C interviews. One Explanation: None.
should practice these 1000+ interview
5. What will be the output of the following C
questions and answers continuously for 2-3
code?
months to clear Citrix interviews on C
Programming language. 1. #include <stdio.h>
Answer: b 7. {
Explanation: None.
8. int a = 6, b = 5;
2. Which type of variables can have the same
9. m(&a, &b);
name in a different function?
a) Global variables 10. printf("%d %d\n", a, b);
b) Static variables
c) Function arguments 11. }
d) Both static variables and Function
arguments a) 5 6
b) 6 5
Answer: d c) 5 5
Explanation: None. d) 6 6
Answer: a 7. }
Explanation: None.
8. void main()
6. What will be the output of the following C
9. {
code?
10. int a = 6, b = 5;
1. #include <stdio.h>
11. m(a, b);
2. void m(int *p)
12. printf("%d %d\n", a, b);
3. {
13. }
4. int i = 0;
a) 0 0 0 0 0 3. {
b) 6 5 3 0 0
4. printf("%d %d\n", p, q);
c) Run time error
d) 6 5 3 junk junk 5. }
9. m(a);
1. #include <stdio.h>
10. }
2. void m(int p, int q)
3. {
a) 6
b) 6 5
4. int temp = p; c) 6 junk value
d) Compile time error
5. p = q;
Answer: d
6. q = temp; Explanation: None.
9. What will be the output of the following C and/or solutions:
code?
1. What will be the output of the following C
1. #include <stdio.h> code?
2. void m(int p) 1. #include <stdio.h>
3. { 2. void main()
4. printf("%d\n", p); 3. {
7. { 6. printf("%p\t%p", p, a);
8. int a = 6, b = 5; 7. }
a) 6 Answer: a
b) 6 5 Explanation: None.
c) 6 junk value
d) Compile time error 2. What will be the output of the following C
code?
Answer: d
Explanation: None. 1. #include <stdio.h>
2. void main()
This section on C quiz focuses on “Pointers
and Arrays”. One shall practice these quizzes 3. {
to improve their C programming skills needed
4. char *s = "hello";
for various interviews (campus interviews,
walkin interviews, company interviews), 5. char *p = s;
placements, entrance exams and other
competitive exams. These questions can be 6. printf("%p\t%p", p, s);
attempted by anyone focusing on learning C
Programming language. They can be a 7. }
beginner, fresher, engineering graduate or an
a) Different address is printed
experienced IT professional. Our C quiz
b) Same address is printed
comes with detailed explanation of the
c) Run time error
answers which helps in better understanding
d) Nothing
of C concepts.
Answer: b
Here is a listing of C quiz on “Pointers and
Explanation: None.
Arrays” along with answers, explanations
3. What will be the output of the following C 5. What will be the output of the following C
code? code?
3. { 3. {
5. char *p = s; 5. char *p = s;
7. } 7. }
Answer: c Answer: d
Explanation: None. Explanation: None.
4. What will be the output of the following C 6. What will be the output of the following C
code? code?
3. { 3. int main()
14. } a) 2 3
b) Compile time error
a) 10 10 c) 2 4
b) Compile time error d) 2 somegarbagevalue
c) 10 1
d) Undefined behaviour Answer: d
Explanation: None.
Answer: c
Explanation: None.
Sanfoundry’s 1000+ Interview Questions &
7. What will be the output of the following C Answers on C helps anyone preparing for
code? Tech Mahindra and other companies C
interviews. One should practice these 1000+
1. #include <stdio.h> interview questions and answers continuously
for 2-3 months to clear Tech Mahindra
2. int main() interviews on C Programming language.
3. { Here is a listing of C programming questions
4. int ary[4] = {1, 2, 3, 4};
on “Address Arithmetic” along with answers,
explanations and/or solutions:
5. int *p = ary + 3;
1. What will be the output of the following C
6. printf("%d\n", p[-2]); code?
7. } 1. #include <stdio.h>
a) 1 2. void main()
b) 2
c) Compile time error 3. {
d) Some garbage value 4. char *s = "hello";
Answer: b 5. char *p = s * 3;
Explanation: None.
6. printf("%c\t%c", *p, s[1]);
8. What will be the output of the following C
code? 7. }
1. #include <stdio.h> a) h e
b) l e
2. int main() c) Compile time error
d) l h
3. {
Answer: c
4. int ary[4] = {1, 2, 3, 4};
Explanation: None.
5. int *p = ary + 3;
2. What will be the output of the following C
6. printf("%d %d\n", p[-2], ar code?
y[*p]);
1. #include <stdio.h> 4. What will be the output of the following C
code?
2. void main()
1. #include <stdio.h>
3. {
2. int main()
4. char *s= "hello";
3. {
5. char *p = s + 2;
4. void *p;
6. printf("%c\t%c", *p, s[1]);
5. int a[4] = {1, 2, 3, 4};
7. }
6. p = &a[3];
a) l e
b) h e 7. int *ptr = &a[2];
c) l l
d) h l 8. int n = (int*)p - ptr;
Answer: b a) -3
Explanation: None. b) 5
c) 4 8. printf("%d\n", *ptr);
d) Compile time error
9. }
Answer: a
Explanation: None. a) 4
b) 3
6. What will be the output of the following C c) Compile time error
code? d) Undefined behaviour
4. char *str = "hello, world\n 3. What will be the output of the following C
"; code?
5. char *strc = "good morning 1. #include <stdio.h>
\n";
2. int main()
6. strcpy(strc, str);
3. {
7. printf("%s\n", strc);
4. char *str = "hello, world!!
8. return 0;
\n";
9. } 5. char strc[] = "good morning
\n";
a) hello, world
b) Crash/segmentation fault 6. strcpy(strc, str);
c) Undefined behaviour
d) Run time error 7. printf("%s\n", strc);
8. return 0;
Answer: b
Explanation: None. 9. }
6. printf("%s\n", str); 3. {
6. return 0; 7. return 0;
7. } 8. }
Answer: c Answer: c
Explanation: None. Explanation: None.
2. What will be the output of the following C 4. What will be the output of the following C
code? code?
3. { 3. {
Answer: c a) 2
Explanation: Since every row in the array b) 4
a[10][5] can contain only 5 characters, the c) 5
a[2] element will hold “fello” i.e. 5 d) 10
characters. There will not be any null
character in a[2]. Since, the array is Answer: c
completely intialized, other rows (row a[3] Explanation: None.
will have only null characters. Hence, printf()
using %s specifier will display fello only. 6. What will be the output of the following C
code?
4. What will be the output of the following C
code? 1. #include <stdio.h>
2. void main() 3. {
5. printf("%s", a[0]); 3. {
Answer: a a) 0
Explanation: None. b) 1
c) Depends on the platform
Sanfoundry’s 1000+ MCQs on C helps d) Depends on the compiler
anyone preparing for placement in Huawei
and other companies. Anyone looking for Answer: b
Huawei placement papers should practice Explanation: None.
these 1000+ questions continuously for 2-3
months, thereby ensuring a top position in 4. What will be the output of the following C
placements. code (run without any command line
arguments)?
Here is a listing of C interview questions on
“Command Line Arguments” along with 1. #include <stdio.h>
answers, explanations and/or solutions:
2. int main(int argc, char *argv[]
)
1. A program that has no command line
arguments will have argc 3. {
a) Zero
b) Negative 4. while (argc--)
c) One
d) Two 5. printf("%s\n", argv[argc]);
6. return 0; 6. return 0;
7. } 7. }
Answer: b Answer: a
Explanation: None. Explanation: None.
5. What will be the output of the following C 7. What will be the output of the following C
code (run without any command line code (run without any command line
arguments)? arguments)?
2. int main(int argc, char *argv[] 2. int main(int argc, char *argv[]
) )
3. { 3. {
6. } 6. return 0;
6. return 0; 9. }
7. { Answer: a
Explanation: None.
4. Which of the following is not possible in 4. return a * b * c;
C?
a) Array of function pointer 5. }
b) Returning a function pointer
6. void main()
c) Comparison of function pointer
d) None of the mentioned 7. {
8. int (function_pointer)(int,
6. What will be the output of the following C int, int);
code?
9. function_pointer = mul;
1. #include <stdio.h>
10. printf("The product of thre
2. int mul(int a, int b, int c) e numbers is:%d",
3. { 5. {
4. return a - b - c; 6. foo(10);
5. } 7. return 0;
6. void main()
8. }
7. { 9. void f(int i)
1. #include <stdio.h>
10. { 2. void f(int (*x)(int));
Answer: a 8. }
Explanation: None.
9. void f(int (*i)(int))
6. What will be the output of the following C
code? 10. {
11. i(11);
1. #include <stdio.h>
12. }
2. void f(int);
13. int myfoo(int i)
3. void (*foo)(float) = f;
14. {
4. int main()
15. printf("%d\n", i);
5. {
16. return i;
6. foo(10);
17. }
7. }
8. void f(int i)
a) Compile time error
b) Undefined behaviour
9. { c) 10 11
d) 10 Segmentation fault
10. printf("%d\n", i);
Answer: d
11. } Explanation: None.
a) Compile time error 8. What will be the output of the following C
b) 10 code?
c) 10.000000
d) Undefined behaviour 1. #include <stdio.h>
5. int main()
1. #include <stdio.h>
6. { answers, explanations and/or solutions:
7. f(foo); 1. What will be the output of the following C
code?
8. }
9. void f(int(*i)(int ))
1. #include <stdio.h>
10. {
2. void main()
11. i(11);
3. {
12. }
4. struct student
14. {
6. int no;
7. char name[20];
15. printf("%d\n", i);
8. };
16. return i;
17. }
9. struct student s;
10. no = 8;
a) 10 11
b) 11 11. printf("%d", no);
c) 10
d) Undefined behaviour 12. }
Answer: b a) Nothing
Explanation: None. b) Compile time error
c) Junk
d) 8
This section on C question bank focuses on
“Complicated Declarations”. One shall Answer: b
practice these questions to improve their C Explanation: None.
programming skills needed for various
interviews (campus interviews, walkin 2. What will be the output of the following C
interviews, company interviews), placements, code?
entrance exams and other competitive exams.
These questions can be attempted by anyone 1. #include <stdio.h>
focusing on learning C Programming
language. They can be a beginner, fresher, 2. struct student
engineering graduate or an experienced IT
professional. Our C question bank comes 3. {
7. void main()
Answer: c
Explanation: None. 8. {
7. char name[20];
Answer: b
Explanation: None. 8. };
9. struct student s; 7. What will be the output of the following C
code?
10. s.no = 8;
1. #include <stdio.h>
11. printf("%s", s.name);
2. int main()
12. }
3. {
a) Nothing
b) Compile time error 4. int *((*x)())[2];
c) Junk
d) 8 5. x();
6. printf("after x\n");
Answer: c
Explanation: None. 7. }
9. {
Answer: a
Explanation: None.
10. s.no = 8;
8. What will be the output of the following C
11. printf("%s", s.name); code?
12. } 1. #include <stdio.h>
1. #include <stdio.h>
5. int main() a) ptr is pointer to int that converts its type to
void
6. { b) ptr is pointer to function passing int
7. x p = f;
returning void
c) ptr is pointer to void that converts its type
8. p(); to int
d) ptr is pointer to function passing void
9. } returning int
10. void (*(f)())(int, float) Answer: b
Explanation: None.
11. {
9. struct student s;
6. What will be the output of the following C
code? 10. s.no = 8;
3. { a) Nothing
b) Compile time error
4. int no;
c) hello
5. char name[20]; d) Varies
6. } Answer: b
Explanation: None.
7. void main()
8. What will be the output of the following C
8. {
code?
9. struct student s;
1. #include <stdio.h>
10. s.no = 8;
2. struct student
11. printf("hello");
3. {
12. }
4. int no;
a) Compile time error 5. char name[20];
b) Nothing
c) hello 6. };
d) Varies
7. void main() Answer: d
Explanation: None.
8. {
10. Is the below declaration legal?
9. student s;
int* ((*x)())[2];
10. s.no = 8;
11. printf("hello");
a) True
b) False
12. } c) Undefined behaviour
d) Depends on the standard
a) Nothing
b) hello Answer: b
c) Compile time error Explanation: None.
d) Varies
Answer: c
Explanation: None.
9. struct student s;
4. Which of the following cannot be a
structure member? 10. s.no = 8;
a) Another structure
b) Function 11. printf("hello");
c) Array
d) None of the mentioned 12. }
3. { 12. }
6. float f; 8. };
7. }; 9. struct student s;
8. int main()
4. What will be the output of the following C
code? 9. {
4. int k; 13. }
12. }
1. #include <stdio.h>
2. struct p a) 3.000000
b) 0.000000
3. { c) Compile time error
d) Undefined behaviour
4. int k;
Answer: b
5. char c;
Explanation: None.
6. float f;
7. };
8. int main()
9. {
10. p x = {.c = 97, .f = 3,
.k = 1};
12. }
9. What will be the output of the following C Here is a listing of C programming questions
code according to C99 standard? on “Structures and Functions” along with
answers, explanations and/or solutions:
1. #include <stdio.h>
1. What will be the output of the following C
2. struct p code?
3. {
1. #include <stdio.h>
4. int k;
2. struct student
5. char c;
3. {
6. float f;
4. char *name;
7. };
5. };
8. int main()
6. struct student s;
9. {
7. struct student fun(void)
10. struct p x = {.c = 97};
8. {
11. printf("%f\n", x.f);
9. s.name = "newton";
12. }
10. printf("%s\n", s.name);
a) 0.000000 11. s.name = "alan";
b) Somegarbagevalue
c) Compile time error 12. return s;
d) None of the mentioned
13. }
Answer: a
14. void main()
Explanation: None.
15. {
This section on C programming questions and
answers focuses on “Structures and 16. struct student m = fun();
Functions”. One shall practice these questions 17. printf("%s\n", m.name);
to improve their C programming skills needed
for various interviews (campus interviews, 18. m.name = "turing";
walkin interviews, company interviews),
placements, entrance exams and other 19. printf("%s\n", s.name);
competitive exams. These questions can be
20. }
attempted by anyone focusing on learning C
Programming language. They can be a a) newton alan alan
beginner, fresher, engineering graduate or an b) alan newton alan
experienced IT professional. Our C c) alan alan newton
programming questions come with detailed d) compile time error
explanation of the answers which helps in
better understanding of C concepts.
Answer: a 1. #include <stdio.h>
Explanation: None.
2. struct temp
2. What will be the output of the following C
3. {
code?
4. int a;
1. #include <stdio.h>
5. } s;
2. struct student
6. void func(struct temp s)
3. {
7. {
4. char *name;
8. s.a = 10;
5. };
9. printf("%d\t", s.a);
6. void main()
10. }
7. {
11. main()
8. struct student s, m;
12. {
9. s.name = "st";
13. func(s);
10. m = s;
14. printf("%d\t", s.a);
11. printf("%s%s", s.name, m.na
me); 15. }
12. }
a) 10 (Garbage Value)
a) Compile time error b) 0 10
b) Nothing c) 10 0
c) Junk values d) (Garbage Value) 10
d) st st
Answer: c
Answer: d Explanation: None.
Explanation: None.
5. Which of the following is not possible
3. Which of the following return-type cannot under any scenario?
be used for a function in C? a) s1 = &s2;
a) char * b) s1 = s2;
b) struct c) (*s1).number = 10;
c) void d) None of the mentioned
d) none of the mentioned
Answer: d
Answer: d Explanation: None.
Explanation: None.
6. Which of the following operation is illegal
4. What will be the output of the following C in structures?
code? a) Typecasting of structure
b) Pointer to a variable of the same structure
c) Dynamic allocation of memory for 17. }
structure
d) All of the mentioned a) alan
b) Turing
Answer: a c) Compile time error
Explanation: None. d) Nothing
5. }; 2. struct point
7. { 4. int x;
9. s.name = "alan"; 6. };
11. } 8. {
15. } 21. {
6. }; 3. {
8. { 5. int y;
9. int x; 6. };
11. }; 8. {
14. { 11. };
Answer: a Answer: a
Explanation: None. Explanation: None.
4. What will be the output of the following C 5. What will be the output of the following C
code? code?
3. { 3. {
4. int x; 4. int x;
5. int y; 5. int y;
6. }; 6. };
8. { 8. int main()
9. int x; 9. {
14. { 14. {
3. {
Answer: a
Explanation: None. 4. char *name;
13. { Answer: d
Explanation: None.
14. struct student m = fun();
2. Comment on the output of the following C
15. printf("%s", m.name); code.
16. }
1. #include <stdio.h>
7. void main()
Answer: a
Explanation: None. 8. {
13. } 4. };
4. int x; 9. {
12. } a) 1
b) 2
13. void foo(struct point p[])
c) 3
14. { d) Compile time error
4. int x;
2. What will be the output of the following C
code? 5. int y;
1. #include <stdio.h> 6. };
3. { 8. int main()
4. int x; 9. {
Answer: b 3. {
9. { 14. {
15. } Answer: c
Explanation: None.
6. What will be the output of the following C 4. int x;
code?
5. int y;
1. #include <stdio.h>
6. };
2. struct point
7. void foo(struct point*);
3. {
8. int main()
4. int x;
9. {
5. int y;
10. struct point p1[] = {1, 2,
6. }; 3, 4, 5};
8. int main()
12. }
12. } 16. }
2. struct student
Answer: a
Explanation: None. 3. {
14. else
This section on C quiz focuses on “Pointer to
Structures”. One shall practice these quizzes 15. printf("falsen");
to improve their C programming skills needed
for various interviews (campus interviews, 16. }
walkin interviews, company interviews),
a) Compile time error
placements, entrance exams and other
b) 1
competitive exams. These questions can be
c) Undefined behaviour
attempted by anyone focusing on learning C
d) false
Programming language. They can be a
beginner, fresher, engineering graduate or an Answer: d
experienced IT professional. Our C quiz Explanation: None.
comes with detailed explanation of the
answers which helps in better understanding 2. What will be the output of the following C
of C concepts. code?
Here is a listing of C quiz on “Pointer to 1. #include <stdio.h>
Structures” along with answers, explanations
and/or solutions: 2. struct p
2. struct p 9. {
10. What will be the output of the following Here is a listing of C programming questions
C code? on “Pointer to Structures” along with
answers, explanations and/or solutions:
1. #include <stdio.h>
1. What will be the output of the following C
2. struct p code?
3. {
1. #include <stdio.h>
4. int x;
2. struct student
5. int y;
3. {
6. };
4. char *c;
7. int main()
5. };
8. {
6. void main()
9. struct p p1[] = {1, 92, 3,
94, 5, 96};
7. {
12. if (x == 3)
10. s->c = "hello";
7. {
Answer: b
Explanation: None. 8. struct student m;
7. { 16. }
4. int x[2];
6. What will be the output of the following C
code? 5. };
2. struct p 7. {
3. { 8. int *x;
4. int x[2]; 9. };
6. struct q 11. {
16. } 2. struct p
Answer: b 6. };
Explanation: None.
7. int main()
8. What will be the output of the following C
code? 8. {
6. }; 13. }
7. int main()
a) Compile time error
8. {
b) Undefined behaviour
c) 1 3
9. struct p p1[] = {1, 2, 3, 4 d) 1 5
, 5, 6};
Answer: d
10. struct p *ptr1 = p1; Explanation: None.
11. printf("%d %d\n", ptr1->x,
(ptr1 + 2)->x); Sanfoundry’s 1000+ Interview Questions &
Answers on C helps anyone preparing for
12. }
AMD and other companies C interviews. One
should practice these 1000+ interview
a) 1 5
questions and answers continuously for 2-3
b) 1 3
months to clear AMD interviews on C
c) Compile time error
Programming language.
d) 1 4
Here is a listing of C question bank on “Self
Answer: a
Referential Structures” along with answers,
Explanation: None.
explanations and/or solutions:
9. What will be the output of the following C
1. What will be the output of the following C
code?
code?
1. #include <stdio.h> 7. void main()
2. struct student 8. {
3. { 9. struct student s;
8. { 14. }
b) hi hey 3. {
c) Run time error
d) hey hey 4. char *c;
9. struct student s;
4. What will be the output of the following C
code? 10. struct student *m = &s;
11. }
2. struct p
3. {
a) 5
b) 9 4. int x;
c) 8
d) 16 5. char y;
Answer: c Answer: b
Explanation: None. Explanation: None.
7. What will be the output of the following C This section on C interview questions and
code? answers focuses on “Self-Referential
1. #include <stdio.h>
Structures”. One shall practice these
interview questions to improve their C
2. typedef struct p *q; programming skills needed for various
interviews (campus interviews, walkin
3. struct p interviews, company interviews), placements,
entrance exams and other competitive exams.
4. {
These questions can be attempted by anyone
5. int x; focusing on learning C Programming
language. They can be a beginner, fresher,
6. char y; engineering graduate or an experienced IT
professional. Our C Interview questions come
7. q ptr; with detailed explanation of the answers
8. };
which helps in better understanding of C
concepts.
9. int main()
Here is a listing of C interview questions on
10. { “Self-Referential Structures” along with
answers, explanations and/or solutions:
11. struct p p = {1, 2, &p};
1. What will be the output of the following C
12. printf("%d\n", p.ptr->x);
code?
13. return 0;
1. #include <stdio.h>
14. }
2. typedef struct p *q;
a) Compile time error
3. int main()
b) 1
c) Undefined behaviour 4. {
d) Address of p
5. struct p
Answer: b
Explanation: None. 6. {
tested by 8. char y;
a) Traveling the list, if NULL is encountered
no loop exists 9. q ptr;
b) Comparing the address of nodes by address
10. }; Answer: b
Explanation: None.
11. struct p p = {1, 2, &p};
3. What will be the output of the following C
12. printf("%d\n", p.ptr->x);
code?
13. return 0;
1. #include <stdio.h>
14. }
2. typedef struct p *q;
a) Compile time error
3. struct p
b) 1
c) Depends on the compiler 4. {
d) None of the mentioned
5. int x;
Answer: a
Explanation: None. 6. char y;
7. q ptr;
2. What will be the output of the following C
code? 8. };
14. }
1. struct node
a) Compile time error
b) 1 2. {
Answer: d c)
Explanation: None.
while (1)
5. Which of the following is not possible {
regarding the structure variable? p = p->next;
if (p == NULL)
a) A structure variable pointing to itself break;
b) A structure variable pointing to another }
structure variable of same type
c) 2 different type of structure variable d) All of the mentioned
pointing at each other
d) None of the mentioned Answer: b
Explanation: None.
Answer: d
Explanation: None. This section on C interview questions and
answers focuses on “Unions”. One shall
6. Which of the following technique is faster
practice these interview questions to improve
for travelling in binary trees?
their C programming skills needed for various
a) Iteration
interviews (campus interviews, walkin
b) Recursion
interviews, company interviews), placements,
c) Both Iteration and Recursion
entrance exams and other competitive exams.
d) Depends from compiler to compiler
These questions can be attempted by anyone
Answer: b focusing on learning C Programming
Explanation: None. language. They can be a beginner, fresher,
engineering graduate or an experienced IT
7. Which of the following will stop the loop professional. Our C Interview questions come
at the last node of a linked list in the with detailed explanation of the answers
following C code snippet? which helps in better understanding of C
concepts.
1. struct node
Here is a listing of C interview questions on
2. { “Unions” along with answers, explanations
and/or solutions:
3. struct node *next;
1. The size of a union is determined by the
4. };
size of the
a) First member in the union
a)
b) Last member in the union
c) Biggest member in the union a) 4
d) Sum of the sizes of all members b) 8
c) 40
Answer: c d) 80
Explanation: None.
Answer: c
2. Which member of the union will be active Explanation: None.
after REF LINE in the following C code?
4. What type of data is holded by variable u
1. #include <stdio.h> int in the following C code?
2. union temp 1. #include <stdio.h>
3. { 2. union u_tag
4. int a; 3. {
7. }; 6. char *sval;
5. int b[10];
Answer: c
Explanation: None.
6. char c;
6. In the following C code, we can access the
7. }u; 1st character of the string sval by using
1. #include <stdio.h> c) 4
d) 32
2. struct
Answer: c
3. {
Explanation: None.
4. char *name;
8. What will be the output of the following C
5. union code?
6. { 1. #include <stdio.h>
8. } u; 3. {
2. union
a) 9
3. { b) Compile time error
c) 16
4. int ival; d) 5
5. float fval; Answer: d
Explanation: None.
6. } u;
8. { 1. #include <stdio.h>
11. } 4. int x;
Answer: d 8. {
Explanation: None.
9. union p p, b;
2. What will be the output of the following C
10. p.y = 60;
code?
11. b.x = 12;
1. #include <stdio.h>
12. printf("%d\n", p.y);
2. union
13. }
3. {
a) Compile time error 6. }k = {.y = 97};
b) Depends on the compiler
c) 60 7. int main()
d) Undefined behaviour
8. {
3. {
Answer: b
Explanation: None.
4. int x;
6. What will be the output of the following C
5. char y; code?
6. }k = {1, 97}; 1. #include <stdio.h>
8. { 3. {
10. } 5. float y;
Answer: d 9. union p p, b;
Explanation: None.
10. p.x = 10;
5. What will be the output of the following C
code? 11. printf("%f\n", p.y);
5. char y;
Answer: b
Explanation: None.
7. Which of the following share a similarity
in syntax?
1. Union, 2. Structure, 3. Arrays and 4.
Pointers
UNIT V FILE
PROCESSING
a) 3 and 4
b) 1 and 2
c) 1 and 3 TOPIC 5.1 INPUT AND OUTPUT
d) 1, 3 and 4 IN C
Answer: b This section on C programming interview
Explanation: None. questions and answers focuses on “File
Access”. One shall practice these interview
8. What will be the output of the following C
questions to improve their C programming
code? (Assuming size of char = 1, int = 4,
skills needed for various interviews (campus
double = 8)
interviews, walkin interviews, company
1. #include <stdio.h>
interviews), placements, entrance exams and
other competitive exams. These questions can
2. union utemp be attempted by anyone focusing on learning
C Programming language. They can be a
3. { beginner, fresher, engineering graduate or an
experienced IT professional. Our C
4. int a;
programming interview questions come with
5. double b; detailed explanation of the answers which
helps in better understanding of C concepts.
6. char c;
Here is a listing of C programming interview
7. }u; questions on “File Access” along with
answers, explanations and/or solutions:
8. int main()
2. What does the following segment of C 5. What will be the output of the following C
code do? code?
fprintf(fp, "Copying!"); 1. #include <stdio.h>
8. }
3. What is FILE reserved word?
a) A structure tag declared in stdio.h a) Compilation error
b) One of the basic data types in c b) 45
c) Pointer to the structure defined in stdio.h c) Nothing
d) It is a type name defined in stdio.h d) Depends on the standard
Answer: d Answer: b
Explanation: None. Explanation: None.
4. What will be the output of the following C 6. stdout, stdin and stderr are
code? a) File pointers
b) File descriptors
1. #include <stdio.h>
c) Streams
2. int main() d) Structure
3. { Answer: a
Explanation: None.
4. FILE *fp = stdin;
7. Which of the following statements about
5. int n;
stdout and stderr are true?
6. fprintf(fp, "%d", 45); a) Same
b) Both connected to screen always
7. } c) Both connected to screen by default
d) stdout is line buffered but stderr is
a) Compilation error unbuffered
b) 45
c) Nothing Answer: c
d) Depends on the standard Explanation: None.
8. What will be the output of the following C c) 65
code? d) Compilation error
2. int main() 9. {
3. { 10. c = getc(fp);
1. #include <stdio.h>
7. }
a) The diagnostic output is directly displayed a) They check for input errors
in the output b) They check for output errors
b) The diagnostic output is pipelined to the
c) They check for all types of errors malloc
d) They check for error in accessing the file d) All of the mentioned
Answer: b Answer: d
Explanation: None. Explanation: None.
a) 3 4. {
b) 1
c) Any length since line did not end with null 5. char line[3];
character
d) Depends on the standard 6. fgets(line, 3, stdin);
7. printf("%d\n", line[2]);
Answer: b
Explanation: None. 8. return 0;
3. Which function will return the current file 7. The functions vprintf(), vfprintf(), and
position for stream? vsprintf() are not equivalent to the
a) fgetpos() corresponding printf() functions except the
b) fseek() variable argument list.
c) ftell() a) true
d) fsetpos() b) false
Answer: c Answer: b
Explanation: The current file position is Explanation: The functions vprintf() ,
returned by ftell() function for stream, or -1L vfprintf() , and vsprintf() are similar to the
on error. corresponding printf() functions except that
the variable argument list is replaced by arg.
4. Select the right explanation for the
following C code snippet.
8. The function reads atmost one less c) reads frequency of c in stream
than the number of characters specified by d) no action is taken by the command
size from the given stream and it is stored in
the string str. Answer: a
a) fget() Explanation: ungetc() pushes c back onto
b) fgets() stream, where it will be returned on the next
c) fput() read. Only one character of pushback per
d) fputs() stream is Guaranteed.