C Interview


Introduction

This site provides all the Basic Interview Questions On C Language in a bunch related to each IT subject present at this site. In the current era, when students are looking for a job then the technical questions related to the programming knowledge are asked into the interview to the interview-person. To prepare the technical round of the interview, job seeker has to clear this round by answering these questions. Here all the technical questions are available in the simplest form so that students can understand easily because this site’s purpose is to provide the easy learning at one click. Here all the C Language Interview Questions And Answers For Freshers are available which goes up to basic level to advance level.

We know that C language is the mother of programming language. Whenever we go for technical interview in the field of technology they ask you for C language. The companies make sure that the candidate should have the knowledge of the C programming. So they ask various questions to the interview person. Here we provide all the possible C language basic interview questions because we know that C is the base language to keep the secure place in the IT companies.

We provide the facility for the frequently asked questions to the students directly without getting any cost from the users. It is totally free service for the students. Here eitworld.com provides the solution for the questions with the easy and simplest answer.

Here we provide all the C Language Basic Interview Questions which are asked in the interview room and asked commonly and provide the better answers to the questions in the efficient way and in the simplest form.

Eitworld.com also covers the various short question answers type to fulfill the requirement of academics. So that students can take the advantage in their exam to lead the marks. We can say that eitworl.com provides the each kind of possible ways to connect the students because we provide the education at one click means all the technology related to the IT are present here. It makes easy for the students who wish to attend the interview and clear it with great success. This successful tutorial is here provided which provides the great experience to the user even that user visits this site first time.

Now Let's see the list of top C Programming interview questions.



1.What is C language?

Answer: C is a general purpose, procedural computer programming language. It was developed by Dennis M. Ritchie in 1972.

2.Which extension is used to save the C program file?

Answer: ".c" extension is used to save the C program file. Like "interview.c".

3.What is the output of 'printf("%d");'?

Answer: printf("%d",a); this will print the value of variable a on the output screen. But as here, there is nothing after the %d, so compiler will show a garbage value on the output screen.

4.What is mean by static keyword in C?

Answer: static keyword is used for defining static variables in C language. This can be used with any data type like int, float, array, pointer, structure, function etc..

Important points about static keyword:

i.Default initial value of static integral type variables are zero otherwise null.

ii.A same static variable can be declared many times but we can initialize at only one time.

iii.If static variable has declared locally or globally its scope will always whole the program.

5.What should be the output of the given program?

#include <stdio.h>
static int x; //Declaring the variable i.
static int x=50; //Initializing the variable.
static int x; //Again declaring the variable i.
int main(){
static int x; //Again declaring the variable i.
printf("%d",x);
return 0;
}
Answer: 50

Explanation : A same static variable can be declared many times but we can initialize at only one time.

6.What should be the output of the given program?

#include <stdio.h>
static int x; //Declaring the variable
static int x=50; //Initializing the variable
int main(){
static int x=60; //Again initializing the variable
printf("%d",x);
return 0;
}
Answer: Compilation error: Multiple initialization variable x.

Explanation: A same static variable can be declared many times but we can initialize at only one time.

7.What should be the output of the given program?

#include <stdio.h>
static int x=10; //Initialization statement
x=25; //Assignment statement
int main(){
printf("%d",i);
return 0;
}
Answer: Compilation error

Explanation: We cannot write any assignment statement globally.

8.What should be the output of the given program?

#include <stdio.h>
int main(){
int i;
for(i=0;i<5;i++)
{
static int x=10;
printf("%d",x++);
}
return 0;
}
Answer: 10 11 12 13 14

Explanation: A static variable initializes only one time in whole program.

9.What is the use of a '\0' character?

Answer: '\0' is referred as a terminating null character; this is basically used to show the end of a string value.

10.What should be the result of the given statement?

A +=15; (assuming the value of A is 10)

Answer: 25

Explanation: A +=15 is a short method of writing A = A + 15, so if the initial value of A is 10, then 10+15 = 25.

11.What are pointers?

Answer: A pointer is a special type of variable which is used to store a memory address of another variable.

12.Can I use "int" data type to store the value 32768? Why?

Answer: No, It is not possible because "int" data type can store the value from -32768 to 32767.

13.What should be the output of the given program?

#include <stdio.h>
#include <stdlib.h>
int main()
{
int a = 20, b = 10, c = 40, d = 30, X ;
X = a/b+c*d-c;
printf(" Value of X = %d\n", X);
return 0;
}
Output: 1162

Explanation:

■ The above arithmetic operation is performed based on the precedence of the operators.

■ In above mentioned expression, c*d will be performed first. Then, a/b, then (c*d)-c, then (a/b) + ((c*d)-c).

■ Please check the operator precedence table to know the priority and associativity of the C operators.

■ Output of the above expression is 1162.

14.What is array?

Answer: Array is a collection of similar data types. Each element of array is unique element that is accessed via index. In C all elements of array are stored in contiguous memory location. The lowest address represents first element and highest address represent last element.

15.What do you mean by Pointer To Pointer?

Answer: A pointer variable can also store the address of another pointer variable. So the pointer variable that contains the address of another pointer variable is known as pointer to pointer.

16.What is structure?

Answer: A structure is a collection of one or more different data-type, grouped together under a single name. Structure is basically used where we have to store complete information for any object like 'student' so all the information of a student like student-name, age, class, phone number etc. can be stored in a structure type variable.

17.What is union?

Answer: Like structure union is also a collection of similar and dissimilar data types but difference is that it holds only one object at a time. As we know in structure every data member has its own memory location but data members of unions have same memory address. Union can contain one member at a time in a single area of storage.

18.What is header file?

Answer: Header file gives the definitions and declarations of the library functions. For example: stdio.h, conio.h, math.h string.h etc..

19.What do you mean by C token?

Answer: The smallest unit of C-program is known as C-token.

20.What is function?

Answer: A function is a block of statements that performs a special task.

21.What are the rules for naming variable?

Answer:

■ Variable name may contain letters, digits and underscore (_) character.

■ The variable name can begin with the letters as well as with underscore (_) character.

■ A variable name should not start with digit.

■ A variable name cannot contain punctuation characters like (@,#,$,%,^,&,* etc)

■ A variable name cannot be a keyword.

■ The variable names may be a combination of uppercase and lowercase characters. For example name and naME are not the same.

22.What do you mean by a variable?

Answer: A variable is a data name given to a data value stored in the memory.

23.How many keywords are present in C language?

Answer: There are 32 keywords present in C language.

24.What should be the output of the given program?

#include<stdio.h>
#include<conio.h>
int main()
{
printf(X);
getch();
return 0;
}
Answer: Compilation error: Undefined symbol 'X'

Explanation: We have not defined the variable X in the given lines of code that's why it gives a compilation error.

25.What do you mean by keyword? Why keywords cannot be used as identifier?

Answer: Keywords are the reserved words which are defined in compiler itself. These keywords contain a special meaning. These are used for specific purpose and they cannot be used as identifier name.

26.What is the use of (*) operator?

Answer: The (*) operator is used for multiplication.

27.Is "12asd" a valid example of identifier, if not then mention the reason?

Answer: It is an invalid example of identifier because the name of identifier can never start with the digits.

28.What will be the output of the following two statements, if initially a=20.

(a)a++<=20 (b) ++a<=20

Answer: The output of the statement (a) will be true because 'a++' is a postfix operator the value of a will be increased after the calculation (20<=20=true). The output of the statement (b) will be false because '++a' is a prefix operator the value of a will be increased before the calculation so (21<=20=false).

29.What do you mean by modulus operator?

Answer: The modulus operator is used to find the remainder of the division. '%' symbol is used for modulus operator. For example: 5 % 3 = 2, meaning when you divide 5 by 3, the remainder is 2.

30.What is the use of a '\n' character?

Answer: '\n' this character is used for changing the line in a c-program.

31.What do you mean by break statement?

Answer: break statement is used for terminating any loop. The control then passes to the statement following the body of the loop.

32.Will the value of a will be same for the two cases given below? (given b=30)

(a) a= ++b (b) a=b++

Answer: No, in case (a), it will be 31 and in case (b), it will be 30.

33.What is the use of a semicolon (;) at the end of every C program statement?

Answer: A semicolon behaves as a delimiter, so that the compiler knows where each C statement ends.

34.What should be the output of the given program?

void main()
{
int const a=5;
printf("%d",++a);
}
Answer: Compiler error: Cannot modify a constant value.

Explanation: a is constant integer we cannot modify a constant value.

35.What should be the output of the given program?

void main()
{
int a=- -4;
printf("%d", a);
}
Answer= 4

Explanation: In this program unary minus operator is used twice. According to mathematics (minus *minus = plus). That is why the output will be positive.

36.What is the default value of static variable?

Answer: The default value of static variable is Null or zero.

37.What should be the output of the given program?

void main()
{
int a;
printf("%d",scanf("%d",&a));
// consider we give the value 5 as a input at run time
}
Answer: 1

Explanation: In the above code scanf function returns the number of items successfully read or not (i.e 1 or 0). Here 5 is given as input which should have been read successfully. So the the number items read is 1.

38.What should be the output of the given program?

#define i 6
void main()
{
#define i 15
printf("%d", i)
}
Answer: 15

Explanation: We can redefine preprocessor directive at anywhere in the program. So the most recently assigned value will be taken.

39.What should be the output of the given program?

#include<stdio.h>
#include<conio.h>
void main()
{
char a;
printf(a);
getch();
}
Answer: Compilation error: Type mismatch in parameter '_format' in call to 'printf'

Explanation: Above code will give the compilation error because we do not mention any format specifier in printf function.

40.What do you mean by continue statement?

Answer: The continue statement forces the program control to go directly to the condition and then continue the next iteration. It means that continue statement stops the current iteration and starts the next iteration.

41.What should be the output of the given program?

#include<stdio.h>
#include<conio.h>
void main()
{
char a='a';
clrscr();
printf("%c,%c,%c",a++,++a,a++);
getch();
}
Answer: The answer of the above program is undefined it is completely depended upon the compiler. Logically its answer should be a c c.

Here's why:

a++ post increments the value of a to 'b';

++a pre increments the value of a to 'c';

a++ post increments the value of a to 'd';

Although you will only see it print out 'c'. But it will show the value of a='d' next time you print a.

42.What do you mean by storage classes?

Answer: Storage classes define the life of variable that is how long a variable would be active in the program. Storage classes also define the scope and storage area of a variable. It also determines the initial value of a variable if it is not initialized.

43.How many storage classes are present in C?

Answer:In C Language storage classes can be categorized into four parts as follows:

■ auto

■ extern

■ static

■ extern

44.What should be the output of the given program?

#include<stdio.h>
#include<conio.h>
void main()
{
int a=7;
clrscr();
printf("%d",a++);
getch();
}
Answer: 7

Explanation: a++ post increments the value of a to 8; Although you will only see it print out 7. But it will show the value of a=8 next time you print a.

45.What should be the output of the given program?

#include<stdio.h>
#include<conio.h>
void main()
{
int a=7;
clrscr();
printf("%d",++a);
getch();
}
Answer: 8

Explanation: ++a pre increments the value of a to 8; So you will only see it print out 8 on the screen.

46.What is the difference between the '++i' and 'i++'?

Answer: ++i increments the value first and then return it but i++ return value first and then increments it.

47.What do you mean by printf()?

Answer: printf() is an output function. printf() function is used to display the data value or message on the output screen. printf() function is a predefined function that is defined in the stdio.h header file.

48.What do you mean by scanf()?

Answer: scanf() is an input function. It is basically used for runtime assignment of variables. scanf() function is a predefined function that is defined in stdio.h header file.

49.Which year C language is developed?

Answer: C language was developed in 1972.

50.What do you mean by constant in C language?

Answer: Constants are the name given to the data values stored in memory and their values cannot be changed at the time of execution.

51.What do you mean by variable in C language?

Answer: A variable is a data name given to a data value stored in the memory. The value of variable can vary at the time of execution.

52.Who developed C language?

Answer: C was developed by the Dennis M. Ritchie.

53.What do you mean by data type in C language?

Answer: Data types determine the type of value stored in any variable or constant.

54.What do you mean by Arithmetic Operators?

Answer: Arithmetic operators are the operators which perform the mathematical operation between two operands.

55.What do you mean by Relational Operators?

Answer: Relational operators are used for the comparison between two values.

56.What do you mean by Logical Operators?

Answer: Logical operators check the logical relationship between the two expressions.

57.What do you mean by Assignment Operators?

Answer: Assignment operators are used to assign the value in variables, arrays or constant.

58.What do you mean by Bitwise Operators?

Answer: Bitwise operators are used to perform operation on binary representation of numeric values.

59.What do you mean by Conditional Operator?

Answer: Conditional operators contain a condition followed by two statements or values. If the condition is true the first statement will be executed otherwise the second statement will be executed.

60.What is the difference between single equal "=" and double equal "==" operators in C?

Answer: Single equal is an assignment operator used to assign the values to the variables but, double equal is relational operator used to compare two variable values whether they are equal or not.

61.What do you mean by Compiler?

Answer: Compiler reads the entire source program and converts it into the object program. Compiler provides errors of entire program at once instead of providing them line by line. Only error free program can be executed.

62.What do you mean by Interpreter?

Answer: Interpreter reads only one line of source program at a time and converts it into the object code. Interpreter provides error line by line.

63.How many keywords are there in C language?

Answer: There are 32 keywords are in C language.

64.Is C language case sensitive?

Answer: Yes, C is a case sensitive language.

65.What is operator in C?

Answer: An Operator performs operations on data value stored in variable, constants and array etc. Operators take one or more operand as input and give a result after applying operation over them. Like in "a+b", 'a' and 'b' are the operands and '+' is an operator which performs the add operation on 'a' and 'b' operands.

66.What do you mean by identifier?

Answer: Identifiers are the name given to the variables, constants, function or array.

67.What do you mean by comments in C- language?

Answer: Those statements which are not executed by the compiler are known as comments.

68.What is the syntax of comment in C-language?

Answer: Syntax: /* This is comment */

The characters or words or anything which are given between "/*" and "*/", won't be considered by C compiler for compilation process. These will be ignored by C compiler during compilation.

69.Can a variable name start with digit?

Answer: No a variable name cannot start with digit.

70.What should be the value of a if a=14/3?

Answer: 4

71.What should be the value of a if a=14%3?

Answer: 2

72.Can we use <> operator in C programming?

Answer: No, it is not the right operator to use in C programming. This operator refers to "not equal to operator". In C programming we use "!=" operator instead of <> operator.

73.Is this statement right? ( mystring = "Sweet" )

Answer: No, this is not a right statement because in c programming we cannot copy the string to a string variable directly by using assignment operator. Instead of this we have to use the strcpy function.

74.What should be the output of the given program?

#include <stdio.h>
int main()
{
int x = 3;
int y = ++x + x;
printf("%d\n", y);
}
Answer: 8

Explanation: ++x pre increments the value of x to 4; Then it will add with the value of x again that is 4.As y=(++x=4)+(4)=8.So the value of y will be 8.

75.What should be the output of the given program?

#include <stdio.h>
int main()
{
int x = 3;
int y = x++ + x;
printf("%d\n", y);
}
Answer: 6

Explanation: x++ post-increments the value of x to 4 although in the calculation the value of x remains 3. But after calculation the value of x will be 4. After that it will add with the value of x again that is 3.As y=(x++=3)+(3)=6.So the value of y will be 6.

76.'%i' format specifier is used for which datatype?

Answer: %i format specifier is used for the int datatype.

77.What is the size of int datatype?

Answer: It is completely depend upon the compiler.

78.Can we use 'auto' as the C variable?

Answer: No, we cannot use the auto as the C variable because auto is the C- keyword.

79.What should be the output of the given program?

#include <stdio.h>
int main()
{
float a = 'c';
printf("%f", a);
return 0;
}
Answer: 99.000000

Explanation: Since the ASCII value of c is 99, the same is assigned to the float variable and printed.

80.What should be the output of the given program?

#include <stdio.h>
int main()
{
float a = 0.5;
if (a == 0.5)
printf("both are equal\n");
else
printf("both are not equal\n");
}
Answer: both are not equal

Explanation: 0.5 by default is of type double which has different representation than float resulting in inequality even after conversion.

81.What should be the output of the given program?

#include <stdio.h>
void main()
{
int a = 6, b, c;
b = --a;
c = a--;
printf("%d %d %d", a, b, c);
}
Answer: 4 5 5

Explanation:

b= --a will equal to 5; -a pre increments the value of a to 5;

c=a-- will equal to 5; a-- post increments the value of a to 4; Although you will only see it store the value 5 in c. But it will show the value of a=4 next time you print a.

That is why its output will be 4 5 5.

82.What should be the output of the given program?

#include <stdio.h>
main()
{
int a = 5, b = 5;
if (a > 5)
if (b > 5)
printf("True");
else
printf("False");
}
Answer: No Output will be printed

83.What should be the output of the given program?

#include <stdio.h>
int main()
{
int x = 4, y = 2, z = 2;
int a;
a = x == (y + z);
printf("%d", a);
}
Answer: 1

Explanation: a = x == (y + z);

In this statement the value of x==(y+z) will be equal to 1 because it is a relational statement which is true and the value of this relational statement that is 1 will be assigned in variable a. That is the why the output of the program will be 1.

84.Can we use the relational operator with structure?

Answer: No,we cannot use the relational operator with structure.

85.Write a C program to print "www.eitworld.com" without using a semicolon.

Answer:

#include<stdio.h>
int main()
{
if( printf( " www.eitworld.com " ) )
{ }
}
86.What is token in C?

Answer: Each and every smallest individual unit in a C program are known as C tokens.

87.What do you mean by void?

Answer: Void is an empty data type that has no value.

88.What is Null pointer?

Answer: Null pointer is a pointer which is pointing to nothing. Null pointer points the empty location in the memory.

89.Can a name of variable start with "@"?

Answer: No, name of variable cannot start with @.

90.Can a name of variable start with underscore (_)?

Answer: Yes, name of variable can start with underscore (_).

91.What is the syntax of comments in C language?

Answer: Syntax: /* your comments here */

92.Can we use the 'if' as the variable name?

Answer: No, we cannot use the if as the variable name because 'if' is a C-Keyword.

93.What do you mean by C-function?

Answer: A function is a block of statements that performs a special task. Functions are the building block of any program.

94.What do you mean by call by value?

Answer: In call by value the copy of actual arguments are passed to the formal arguments. In this case all the operation is done on the formal arguments it does not made any change in the actual argument because formal arguments are the photocopy of the actual arguments. It means that all the changes made in the formal argument are local to the block of called function.

95.What do you mean by call by reference?

Answer: In call by reference instead of value, address of value is passed. So in this case function copies the address of an argument into the formal parameter. In Call by reference formal arguments are works as the pointer that points to the actual arguments so the changes made to the formal arguments are permanent. So in this type changes made to the formal argument also affect the actual argument.

96.What do you mean by actual parameter?

Answer: Parameter Written In Function Call is Called "Actual Parameter".

97.What do you mean by formal parameter?

Answer: Parameter Written In Function Definition is Called "Formal Parameter"

98.Tell any difference between C and C++?

Answer: C is structure/procedure oriented programming language whereas C++ is object oriented programming language.

99.What is Dangling pointer?

Answer: Dangling Pointer is a pointer that doesn't point to a valid memory location.

100.Are pointers Integer?

Answer: No, pointers are not integer. A pointer is an address.