C lang Interview Questions (Ed Spread)
C lang Interview Questions (Ed Spread)
F A L L I N T H E L O O P O F T E C H
C PROGRAMMING
INTERVIEW
QUESTIONS
ED SPREAD
F A L L I N T H E L O O P O F T E C H
Compilers and interpreters often deal with how program codes are
executed.
Interpreters execute program codes one line at a time, while compilers
take the program as a whole and convert it into object code, before
executing it.
The key difference here is that in the case of interpreters, a program
may encounter syntax errors in the middle of execution, and will stop
from there.
On the other hand, compilers check the syntax of the entire program
and will only proceed to execution when no syntax errors are found.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
No. “int” data type is capable of storing values from -32768 to 32767.
To store 32768, you can use “long int” instead.
You can also use “unsigned int”, assuming you don’t intend to store
negative values.
1
12
123
1234
12345
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is debugging?
Debugging is the process of identifying errors within a program.
During program compilation, errors that are found will stop the
program from executing completely.
At this state, the programmer would look into the possible portions
where the error occurred.
Debugging ensures the removal of errors, and plays an important role in
ensuring that the expected program output is met.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is typedef?
typedef is a C keyword, used to define alias/synonyms for an existing
type in C language.
In most cases, we use typedef's to simplify the existing type declaration
syntax.
Or to provide specific descriptive names to a type.
#include<stdio.h>
int main()
{
int x;
printf("Enter a number: ");
scanf("%d", &x);
(x&1)?printf("Odd"):printf("Even");
return 0;
}
What is recursion in C?
When a function calls itself, and this process is known as recursion.
The function that calls itself is known as a recursive function.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
// method 1
printf("%d\n", x-(-y));
// method 2
printf("%d\n", -(-x-y));
// method 3
printf("%d\n", abs(-x-y));
// method 4
printf("%d", x-(~y)-1);
return 0;
}
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
Output=1
The do-while loop executes at every iteration.
After the continue statement, it will come to the while (false)
statement, and the condition shows false, and ‘i’ is printed only once.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is an array in C?
An Array is a group of similar types of elements.
It has a contiguous memory location.
It makes the code optimized, easy to traverse and easy to sort.
The size and type of arrays cannot be changed after its declaration.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is a pointer in C?
A pointer is a variable that refers to the address of a value.
It makes the code optimized and makes the performance fast.
Whenever a variable is declared inside a program, then the system
allocates some memory to a variable.
The memory contains some address number.
The variables that hold this address number is known as the pointer
variable.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is a file?
A file is a region of storage in hard disks or in auxiliary storage devices. It
contains bytes of
information .It is not a data type.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
In C language, the external static variable has the internal linkage and
the internal static variable has no linkage.
It is the reason they have a different scope but both will alive
throughout the program.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
#include <stdio.h>
int main()
{
int pos = 14;
float data = 1.2;
printf("%*f",pos,data);
return 0;
}
The output of the above code will be 1.200000 with 6 space.
#include <stdio.h>
int main()
{
int data = 16;
data = data >> 1;
printf("%d\n", data );
return 0;
}
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is a C Token?
Keywords, Constants, Special Symbols, Strings, Operators, Identifiers
used in C program are referred to as C Tokens.
What is /0 character?
The Symbol mentioned is called a Null Character. It is considered as the
terminating character used in strings to notify the end of the string to
the compiler.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is typecasting?
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
Function Operation
fopen() To Open a File
fclose() To Close a File
fgets() To Read a File
fprint() To Write into a File
#include<stdio.h>
void main(){
if(printf("hello world")){}
}
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is union in C?
The union is also user-defined data type.
Union allows to combine data items of different kinds. Union doesn’t
occupy the sum of the memory of all members.
It holds only the memory of the largest member only. In union, we can
access only one variable at a time.
It allocates one common space for all the members of a union.
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
+91-7842584260 www.edspread.in
ED SPREAD
F A L L I N T H E L O O P O F T E C H
What is macro?
A macro is a pre-processor directive and it replaces the value before
compiling the code.
One of the major problems with the macro is that there is no type
checking.
Generally, the macro is used to create the alias, in C language.
A macro is also used as a file guard in C and C++.
+91-7842584260 www.edspread.in