Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Predict the output of following program. Assume that the numbers are stored in 2’s complement form.#include<stdio.h>int main(){unsigned int x = -1;int y = ~0;if (x == y)printf("same");elseprintf("not same");return 0;}(A) same(B) not same

Answer»
2.

Output?int main(){void *vptr, v;v = 0;vptr = &v;printf("%v", *vptr);getchar();return 0;}(A) 0(B) Compiler Error(C) Garbage Value

Answer»
3.

#include <stdio.h>int main(){if (sizeof(int) > -1)printf("Yes");elseprintf("No");return 0;}(A) Yes(B) No(C) Compiler Error(D) Runtime Error

Answer»
4.

Output of following program?#include<stdio.h>int main(){float x = 0.1;if ( x == 0.1 )printf("IF");else if (x == 0.1f)printf("ELSE IF");elseprintf("ELSE");}(A) ELSE IF(B) IF(C) ELSE

Answer»
5.

Predict the output of following C program#include <stdio.h>int main(){char a = 012;printf("%d", a);return 0;}(A) Compiler Error(B) 12(C) 10(D) Empty

Answer»
6.

Predict the output#include <stdio.h>int main(){float c = 5.0;printf ("Temperature in Fahrenheit is %.2f", (9/5)*c + 32);return 0;}(A) Temperature in Fahrenheit is 41.00(B) Temperature in Fahrenheit is 37.00(C) Temperature in Fahrenheit is 0.00(D) Compiler Error

Answer» None
7.

Where in C the order of precedence of operators do not exist?(a) Within conditional statements, if, else(b) Within while, do-while(c) Within a macro definition(d) None of the mentionedI got this question during an interview for a job.My doubt stems from Precedence and Order of Evaluation in chapter Data Types, Operators and Expressions in C of C

Answer» CORRECT ANSWER is (d) NONE of the mentioned

For EXPLANATION: None.
8.

Which of the following operator has the highest precedence in the following?(a) ()(b) sizeof(c) *(d) +The question was posed to me during an interview for a job.This is a very interesting question from Precedence and Order of Evaluation topic in division Data Types, Operators and Expressions in C of C

Answer» RIGHT ANSWER is (a) ()

BEST EXPLANATION: NONE.
9.

Which keyword is used to prevent any changes in the variable within a C program?(a) immutable(b) mutable(c) const(d) volatileThis question was addressed to me during an internship interview.The question is from Declarations in section Data Types, Operators and Expressions in C of C

Answer» RIGHT choice is (C) const

The EXPLANATION is: const is a keyword constant in C program.
10.

Which of the following declaration is illegal?(a) char *str = “Best C programming classes by Sanfoundry”;(b) char str[] = “Best C programming classes by Sanfoundry”;(c) char str[20] = “Best C programming classes by Sanfoundry”;(d) char[] str = “Best C programming classes by Sanfoundry”;This question was addressed to me by my college professor while I was bunking the class.The doubt is from Declarations topic in division Data Types, Operators and Expressions in C of C

Answer»

Right choice is (d) CHAR[] str = “BEST C programming classes by Sanfoundry”;

The EXPLANATION is: char[] str is a declaration in Java, but not in C.

11.

Why do variable names beginning with the underscore is not encouraged?(a) It is not standardized(b) To avoid conflicts since assemblers and loaders use such names(c) To avoid conflicts since library routines use such names(d) To avoid conflicts with environment variables of an operating systemThis question was posed to me by my school principal while I was bunking the class.Asked question is from Variable Names in portion Data Types, Operators and Expressions in C of C

Answer» RIGHT ANSWER is (c) To avoid conflicts SINCE LIBRARY routines use such names

Explanation: None.
12.

Which of the following is not a valid variable name declaration?(a) int __a3;(b) int __3a;(c) int __A3;(d) None of the mentionedI got this question during an online interview.My doubt is from Variable Names in chapter Data Types, Operators and Expressions in C of C

Answer» CORRECT CHOICE is (d) NONE of the mentioned

The BEST EXPLANATION: None.
13.

Operation “a = a * b + a” can also be written as ___________(a) a *= b + 1;(b) (c = a * b)!=(a = c + a);(c) a = (b + 1)* a;(d) All of the mentionedI got this question in a job interview.This interesting question is from Assignment Operators & Expressions in chapter Data Types, Operators and Expressions in C of C

Answer» CORRECT ANSWER is (d) All of the mentioned

Explanation: NONE.
14.

function tolower(c) defined in library works for ___________(a) Ascii character set(b) Unicode character set(c) Ascii and utf-8 but not EBCDIC character set(d) Any character setI have been asked this question in an interview for internship.The origin of the question is Type Conversions topic in chapter Data Types, Operators and Expressions in C of C

Answer»

The CORRECT CHOICE is (d) Any CHARACTER set

To EXPLAIN I would SAY: None.

15.

Which of the following is not a valid variable name declaration?(a) int _a3;(b) int a_3;(c) int 3_a;(d) int _3aI got this question in an interview for internship.This question is from Variable Names topic in chapter Data Types, Operators and Expressions in C of C

Answer»

The correct answer is (c) int 3_a;

EASY explanation - VARIABLE NAME cannot start with a digit.

16.

C99 standard guarantees uniqueness of ___________ characters for external names.(a) 31(b) 6(c) 12(d) 14I got this question in final exam.Question is from Variable Names in division Data Types, Operators and Expressions in C of C

Answer» RIGHT choice is (a) 31

Best EXPLANATION: ISO C99 COMPILER may consider only first 31 characters for external names.
17.

Which of the following type-casting have chances for wrap around?(a) From int to float(b) From int to char(c) From char to short(d) From char to intThis question was addressed to me in exam.I'm obligated to ask this question of Type Conversions in chapter Data Types, Operators and Expressions in C of C

Answer» RIGHT option is (b) From int to char

Easiest EXPLANATION - NONE.
18.

Which type of conversion is NOT accepted?(a) From char to int(b) From float to char pointer(c) From negative int to char(d) From double to charI have been asked this question in unit test.Question is taken from Type Conversions topic in division Data Types, Operators and Expressions in C of C

Answer»

The correct option is (B) From float to char POINTER

Best EXPLANATION: CONVERSION of a float to pointer type is not ALLOWED.

19.

Which of the following is not an arithmetic operation?(a) a * = 10;(b) a / = 10;(c) a ! = 10;(d) a % = 10;I got this question during an interview.This is a very interesting question from Arithmetic Operators in chapter Data Types, Operators and Expressions in C of C

Answer»

The correct choice is (c) a ! = 10;

EXPLANATION: NONE.

20.

Which of the following is possible with any 2 operators in C?(a) Same associativity, different precedence(b) Same associativity, same precedence(c) Different associativity, different precedence(d) All of the mentionedThe question was asked by my college director while I was bunking the class.My question is based upon Precedence and Order of Evaluation in section Data Types, Operators and Expressions in C of C

Answer»

Right CHOICE is (d) All of the mentioned

To explain I WOULD SAY: NONE.

21.

Which of the following is NOT possible with any 2 operators in C?(a) Different precedence, same associativity(b) Different precedence, different associativity(c) Same precedence, different associativity(d) All of the mentionedThe question was asked by my school teacher while I was bunking the class.My enquiry is from Precedence and Order of Evaluation topic in portion Data Types, Operators and Expressions in C of C

Answer»

Correct CHOICE is (C) Same PRECEDENCE, DIFFERENT associativity

For explanation: None.

22.

Which of the following is not a pointer declaration?(a) char a[10];(b) char a[] = {‘1’, ‘2’, ‘3’, ‘4’};(c) char *str;(d) char a;I had been asked this question in my homework.My doubt is from Declarations topic in portion Data Types, Operators and Expressions in C of C

Answer» CORRECT CHOICE is (d) CHAR a;

BEST explanation: Array declarations are POINTER declarations.
23.

Which data type is most suitable for storing a number 65000 in a 32-bit system?(a) signed short(b) unsigned short(c) long(d) intThe question was asked by my college director while I was bunking the class.Question is from Data Types and Sizes in section Data Types, Operators and Expressions in C of C

Answer» CORRECT option is (b) UNSIGNED short

The best I can explain: 65000 comes in the range of short (16-bit) which occupies the LEAST memory. SIGNED short ranges from -32768 to 32767 and hence we should use unsigned short.
24.

Do logical operators in the C language are evaluated with the short circuit?(a) True(b) False(c) Depends on the compiler(d) Depends on the standardI have been asked this question during an online exam.I want to ask this question from Relational & Logical Operators in division Data Types, Operators and Expressions in C of C

Answer» CORRECT OPTION is (a) True

The BEST I can EXPLAIN: NONE.
25.

What is the result of logical or relational expression in C?(a) True or False(b) 0 or 1(c) 0 if an expression is false and any positive number if an expression is true(d) None of the mentionedThis question was addressed to me in a national level competition.My question comes from Relational & Logical Operators in division Data Types, Operators and Expressions in C of C

Answer» CORRECT OPTION is (B) 0 or 1

For EXPLANATION: None.
26.

Which of the following is not a valid variable name declaration?(a) float PI = 3.14;(b) double PI = 3.14;(c) int PI = 3.14;(d) #define PI 3.14The question was asked in an online interview.Asked question is from Variable Names in section Data Types, Operators and Expressions in C of C

Answer»

Correct answer is (d) #DEFINE PI 3.14

Easiest explanation - #define PI 3.14 is a macro preprocessor, it is a TEXTUAL SUBSTITUTION.

27.

A variable declared in a function can be used in main().(a) True(b) False(c) True if it is declared static(d) None of the mentionedI got this question in a national level competition.I'd like to ask this question from Declarations in division Data Types, Operators and Expressions in C of C

Answer»

The CORRECT answer is (b) False

Explanation: SINCE the SCOPE of the variable DECLARED within a function is restricted only within that function, so the above STATEMENT is false.

28.

C99 standard guarantees uniqueness of __________ characters for internal names.(a) 31(b) 63(c) 12(d) 14This question was posed to me in my homework.My question comes from Variable Names topic in division Data Types, Operators and Expressions in C of C

Answer»

Correct CHOICE is (b) 63

The explanation is: ISO C99 compiler MAY consider only first 63 characters for internal NAMES.

29.

Which is correct with respect to the size of the data types?(a) char > int > float(b) int > char > float(c) char < int < double(d) double > char > intI got this question in an online interview.The above asked question is from Data Types and Sizes in division Data Types, Operators and Expressions in C of C

Answer» CORRECT answer is (C) CHAR < int < double

To explain I WOULD say: char has less bytes than int and int has less bytes than double in any system
30.

Which of the following are unary operators?(a) sizeof(b) –(c) ++(d) all of the mentionedI have been asked this question in a job interview.The origin of the question is Precedence and Order of Evaluation topic in chapter Data Types, Operators and Expressions in C of C

Answer»

Correct choice is (d) all of the mentioned

To EXPLAIN I WOULD say: NONE.

31.

Which among the following is NOT a logical or relational operator?(a) !=(b) ==(c) ||(d) =I have been asked this question in examination.My question is taken from Relational & Logical Operators topic in division Data Types, Operators and Expressions in C of C

Answer» CORRECT CHOICE is (d) =

For EXPLANATION: NONE.
32.

Which of the following typecasting is accepted by C?(a) Widening conversions(b) Narrowing conversions(c) Widening & Narrowing conversions(d) None of the mentionedI got this question in an international level competition.I want to ask this question from Type Conversions topic in chapter Data Types, Operators and Expressions in C of C

Answer»

Right CHOICE is (c) WIDENING & Narrowing conversions

Easiest explanation - NONE.

33.

What is the precedence of arithmetic operators (from highest to lowest)?(a) %, *, /, +, –(b) %, +, /, *, –(c) +, -, %, *, /(d) %, +, -, *, /This question was addressed to me during an online exam.This interesting question is from Arithmetic Operators topic in chapter Data Types, Operators and Expressions in C of C

Answer»

The CORRECT ANSWER is (a) %, *, /, +, –

Best EXPLANATION: NONE.

34.

Associativity of an operator is ___________(a) Right to Left(b) Left to Right(c) Random fashion(d) Both Right to Left and Left to RightThe question was asked during an internship interview.My question comes from Precedence and Order of Evaluation topic in chapter Data Types, Operators and Expressions in C of C

Answer»

Correct ANSWER is (d) Both RIGHT to LEFT and Left to Right

The EXPLANATION is: None.

35.

Which of the following is a User-defined data type?(a) typedef int Boolean;(b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;(c) struct {char name[10], int age};(d) all of the mentionedThe question was posed to me in semester exam.The above asked question is from Data Types and Sizes in chapter Data Types, Operators and Expressions in C of C

Answer»

The correct OPTION is (d) all of the mentioned

Best EXPLANATION: TYPEDEF and struct are used to define user-defined DATA TYPES.

36.

Which is valid C expression?(a) int my_num = 100,000;(b) int my_num = 100000;(c) int my num = 1000;(d) int $my_num = 10000;I got this question during a job interview.My doubt is from Variable Names topic in portion Data Types, Operators and Expressions in C of C

Answer» RIGHT answer is (b) INT my_num = 100000;

To explain I would say: Space, comma and $ cannot be USED in a variable name.
37.

Which of the following operators has an associativity from Right to Left?(a)

Answer» RIGHT CHOICE is (d) +=

For EXPLANATION: NONE.
38.

Which of the following statement is false?(a) A variable defined once can be defined again with different scope(b) A single variable cannot be defined with two different types in the same scope(c) A variable must be declared and defined at the same time(d) A variable refers to a location in memoryThe question was posed to me in quiz.I need to ask this question from Declarations in portion Data Types, Operators and Expressions in C of C

Answer» RIGHT option is (c) A variable MUST be declared and DEFINED at the same time

Explanation: It is not an ERROR if the variable is declared and not defined. For example – extern declarations.
39.

Variable name resolution (number of significant characters for the uniqueness of variable) depends on ___________(a) Compiler and linker implementations(b) Assemblers and loaders implementations(c) C language(d) None of the mentionedThe question was posed to me in an internship interview.My enquiry is from Variable Names topic in division Data Types, Operators and Expressions in C of C

Answer»

The CORRECT option is (a) Compiler and LINKER implementations

The explanation: It depends on the STANDARD to which compiler and linkers are adhering.

40.

All keywords in C are in ____________(a) LowerCase letters(b) UpperCase letters(c) CamelCase letters(d) None of the mentionedI got this question during a job interview.My enquiry is from Variable Names topic in portion Data Types, Operators and Expressions in C of C

Answer» RIGHT OPTION is (a) LOWERCASE letters

For EXPLANATION: NONE.
41.

Which of the following method is accepted for assignment?(a) 5 = a = b = c = d;(b) a = b = c = d = 5;(c) a = b = 5 = c = d;(d) None of the mentionedThe question was posed to me in exam.This is a very interesting question from Precedence and Order of Evaluation topic in division Data Types, Operators and Expressions in C of C

Answer»

Right ANSWER is (B) a = b = c = d = 5;

The best explanation: None.

42.

Are logical operator sequence points?(a) True(b) False(c) Depends on the compiler(d) Depends on the standardI have been asked this question in an international level competition.The doubt is from Relational & Logical Operators in section Data Types, Operators and Expressions in C of C

Answer» CORRECT CHOICE is (a) True

The BEST EXPLANATION: NONE.
43.

Which of the following data type will throw an error on modulus operation(%)?(a) char(b) short(c) int(d) floatI got this question in an interview.This key question is from Arithmetic Operators in division Data Types, Operators and Expressions in C of C

Answer» CORRECT ANSWER is (d) float

To EXPLAIN: NONE.
44.

What is the size of an int data type?(a) 4 Bytes(b) 8 Bytes(c) Depends on the system/compiler(d) Cannot be determinedI have been asked this question during an online interview.Question is taken from Data Types and Sizes in section Data Types, Operators and Expressions in C of C

Answer»

Right ANSWER is (c) Depends on the system/compiler

Explanation: The SIZE of the DATA types DEPEND on the system.