Académique Documents
Professionnel Documents
Culture Documents
com
Top 80
C Programming
Interview Questions and Answers
jobsiit.com
QUESTION 1
What is C language?
ANSWER
C is a structured, procedural programming language that has been widely used both for
operating systems and applications and that has had a wide following in the academic
community.
jobsiit.com
QUESTION 2
Who invented C language?
ANSWER
In 1972, Dennis Ritchie developed a new language by combining features from BCPL and
B and adding some additional features naming the language as C.
jobsiit.com
QUESTION 3
What are the features of C language?
ANSWER
The C compiler combines the capabilities of an assembly language with features of a
high-level language.
Programs Written in C are efficient and fast. This is due to its variety of data type and
powerful operators.
C is highly portable this means that programs once written can be run on another
machines with little or no modification.
Another important feature of C program, is its ability to extend itself.
jobsiit.com
QUESTION 4
What are the uses of C language?
ANSWER
C is often used for "system programming", including implementing operating
systems and embedded system applications, due to a combination of desirable
characteristics such as code portability and efficiency.
jobsiit.com
QUESTION 5
What do you mean by a Constant?
ANSWER
Constants are also like normal variables. But, only difference is, their values cant be
modified by the program once they are defined.
They refer to fixed values
ANSWER
An integer constant must have at least one digit
It must not have a decimal point
It can either be positive or negative
jobsiit.com
jobsiit.com
QUESTION 7
What do you mean by a Variable?
ANSWER
Variables are simply names used to refer to some location in memory a location that
holds a value with which we are working.
It may help to think of variables as a placeholder for a value.
ANSWER
Variable name must begin with letter or underscore
Variables are case sensitive
They can be constructed with digits, letters
jobsiit.com
jobsiit.com
QUESTION 9
What are data types? Name the different types of data types in C language.
ANSWER
Data types are defined as the data storage format that a variable can store a data to
perform a specific operation.
Types of data types:
jobsiit.com
QUESTION 10
What is the purpose of the String() function?
ANSWER
C Strings are nothing but array of characters ended with null character (\0). This null
character indicates the end of the string. Strings are always enclosed by double quotes.
jobsiit.com
QUESTION 11
What do you mean by tokens and keywords?
ANSWER
Tokens are the basic buildings blocks in C language which are constructed together to
write a C program. Each and every smallest individual units in a C program are known
as Tokens.
Keywords are pre-defined words in a C compiler. Each keyword is meant to perform a
specific function in a C program.
jobsiit.com
QUESTION 12
What is the difference between constant and volatile keyword?
ANSWER
Constants are also like normal variables. But, only difference is, their values cant be
modified by the program once they are defined.
They refer to fixed values
ANSWER
C language offers many types of operators. They are:
1.
Arithmetic operators
2.
Assignment operators
3.
Relational operators
4.
Logical operators
5.
6.
Conditional operators
7.
Special operators
For Computer Science related jobs visit www.jobsiit.com
jobsiit.com
jobsiit.com
QUESTION 14
What is the difference between operators and expressions?
ANSWER
An operator is a symbol that tells the compiler to perform specific mathematical or
logical manipulations.
jobsiit.com
QUESTION 15
What is a loop?
ANSWER
Loops are used to repeat a block of code. Being able to have your program repeatedly
execute a block of code is one of the most basic but useful tasks in programming - many
programs or websites that produce extremely complex output are really only executing
a single task many times.
jobsiit.com
QUESTION 16
What are the rules for constructing a identifier name in C?
ANSWER
The first character of the variable name must either be alphabet or underscore
No commas and blanks are allowed in the variable name
No special symbols other than underscore are allowed in the variable name
jobsiit.com
QUESTION 17
What is syntax error?
ANSWER
Syntax error is a mistake in the syntax of some strange sequence of characters
or tokens that is intended to be stated in a particular programming language.
jobsiit.com
QUESTION 18
What is a local block?
ANSWER
A local block is any portion of a C program that is enclosed by the left brace ({) and the
right brace (}). A C function contains left and right braces, and therefore anything
between the two braces is contained in a local block. An if statement or
a switch statement can also contain braces, so the portion of code between these two
braces would be considered a local block.
jobsiit.com
QUESTION 19
Should variables be stored in local block?
ANSWER
The use of local blocks for storing variables is unusual and therefore should be avoided,
with only rare exceptions. One of these exceptions would be for debugging purposes,
when you might want to declare a local instance of a global variable to test within your
function. You also might want to use a local block when you want to make your program
more readable in the current context.
jobsiit.com
QUESTION 20
When is switch statement better than multiple if statements?
ANSWER
Switch statement is generally best to use when you have more than two conditional
expressions based on a single variable of numeric type.
jobsiit.com
QUESTION 21
Can the last case of a switch statement skip including the break?
ANSWER
Even though the last case of a switch statement does not require a break statement at
the end, you should add break statements to all cases of the switch statement, including
the last case. You should do so primarily because your program has a strong chance of
being maintained by someone other than you who might add cases but neglect to
notice that the last case has no break statement.
jobsiit.com
QUESTION 22
What is the difference between goto and long jmp( ) and setjmp()?
ANSWER
A goto statement implements a local jump of program execution, and
the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program
execution. Generally, a jump in execution of any kind should be avoided because it is not
considered good programming practice to use such statements as goto and longjmp in
your program.
jobsiit.com
QUESTION 23
What is a rvalue?
ANSWER
rvalue can be defined as an expression that can be assigned to an lvalue.
The rvalue appears on the right side of an assignment statement.
jobsiit.com
QUESTION 24
Can an array be an 1value?
ANSWER
The answer to this question is no, because a n array is composed of several separate
array elements that cannot be treated as a whole for assignment purposes.
jobsiit.com
QUESTION 25
When is the "void" keyword used in a function?
ANSWER
The void keyword allows you to define a function that returns no data.
Functions that do not return any value are sometimes referred to as procedures or
subroutines.
jobsiit.com
QUESTION 26
What are the difference between malloc() and calloc()?
ANSWER
Calloc is used to allocate a block of memory, the allocated region is initialized to
zeroes.
Malloc does not touch the contents of the allocated block of memory, which means it
contains garbage values.
jobsiit.com
QUESTION 27
Is the left to right or right to left order gauranteed for operator precedence?
ANSWER
The simple answer to this question is neither. The C language does not always evaluate
left-to-right or right-to-left. Generally, function calls are evaluated first, followed by
complex expressions and then simple expressions.
ANSWER
If
If else
Nested if
jobsiit.com
jobsiit.com
QUESTION 29
What are the advantages of using pointers?
ANSWER
Pointers are more efficient in handling arrays and data tables
They can be used to return multiple values from a function via function arguments
Pointers permit references to functions
jobsiit.com
QUESTION 30
What is a static variable?
ANSWER
A static variable is a variable that has been allocated staticallywhose lifetime or
"extent" extends across the entire run of the program.
jobsiit.com
QUESTION 31
What is the difference between declaring a variable and defining a variable?
ANSWER
When you declare a variable, a function, or even a class all you are doing is saying:
there is something with this name, and it has this type.
Defining something means providing all of the necessary information to create that
thing in its entirety.
jobsiit.com
QUESTION 32
Where is an auto variable stored?
ANSWER
They are stored in main memory. Memory is allocated to an automatic variable when
the block which contains it is called and it is de-allocated at the completion of its
block execution.
jobsiit.com
QUESTION 33
How are errors handled in C language?
ANSWER
C programming does not provide direct support for error handling but being a system
programming language, it provides you access at lower level in the form of return
values.
C programmer can check the returned values and can take appropriate action
depending on the return value.
jobsiit.com
QUESTION 34
What do you mean by a storage class? Name the storage classes which can be used in a
C Program?
ANSWER
A storage class in C is an attribute that tells us where the variable would be stored, what
will be the initial value of the variable if no value is assigned to that variable.
ANSWER
Rules for constructing identifier name in C:
First character should be an alphabet or underscore
Succeeding characters might be digits or letter
jobsiit.com
jobsiit.com
QUESTION 36
What are case control statement? Name the types of case control statements in C
language.
ANSWER
The statements which are used to execute only specific block of statements in a series of
blocks are called case control statements.
jobsiit.com
QUESTION 37
What is the scope of register and static variables?
ANSWER
Register is used to define local variables that should be stored in a register instead of
RAM.
Static is the default storage class for global variables. The two variables count and road
both have a static storage class.
jobsiit.com
QUESTION 38
What is the use of printf and scanf function?
ANSWER
printf() function is used to print the character, string, float, integer, octal and
hexadecimal values onto the output screen.
scanf() function is used to read character, string, numeric data from the keyboard.
jobsiit.com
QUESTION 39
What is debugging?
ANSWER
Debugging is the process of locating and fixing or bypassing bugs (errors) in computer
program code or the engineering of a hardware device.
jobsiit.com
QUESTION 40
What is FIFO and LIFO?
ANSWER
FIFO (first-in, first-out) is an approach to handling program work requests from queues
or stacks so that the oldest request is handled next.
LIFO (last-in, first-out) is an approach in which the most recent request is handled next
and the oldest request doesn't get handled.
jobsiit.com
QUESTION 41
What is the && operator and how does it function in a program code?
ANSWER
The && is also known as AND operator and returns the boolean value true if both
operands are true and returns false.
The operands are implicitly converted to type bool prior to evaluation, and the result
is of type bool.
Logical AND has left-to-right associativity.
jobsiit.com
QUESTION 42
What is the difference between break and continue statements?
ANSWER
The break statement is used to exit the current loop before its normal ending.
The continue statement resumes iteration of a
enclosing for, while, until or select loop.
jobsiit.com
QUESTION 43
Elaborate the buffer manipulation function?
ANSWER
Buffer manipulation functions in C work on the address of the memory block rather
than the values inside the address.
jobsiit.com
QUESTION 44
What is call by reference in functions?
ANSWER
The call by reference method of passing arguments to a function copies the address of
an argument into the formal parameter.
Inside the function, the address is used to access the actual argument used in the call.
jobsiit.com
QUESTION 45
Which is a better option in C Language Macros or Functions?
ANSWER
Macros are more faster and efficient as compared to functions but complex
programming cannot be handled by macros so whether to use macros or functions
depends on the priority as well as use.
jobsiit.com
QUESTION 46
What is a memory leak? How can it be avoided?
ANSWER
Memory leak occurs when programmers create a memory in heap and forget to
delete it.
To avoid memory leaks, memory allocated on heap should always be freed when no
longer needed.
jobsiit.com
QUESTION 47
What is gets( ) function?
ANSWER
In the C Programming Language, the gets function reads characters from
the stdin stream and stores them in s. The gets function returns s.
jobsiit.com
QUESTION 48
What do you mean by a nested loop?
ANSWER
A nested loop is a loop within a loop, an inner loop within the body of an outer one.
How this works is that the first pass of the outer loop triggers the inner loop, which
executes to completion. Then the second pass of the outer loop triggers the
inner loop again.
jobsiit.com
QUESTION 49
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
ANSWER
The process of allocating memory during program execution is called dynamic
memory allocation.
jobsiit.com
QUESTION 50
What are the uses of Static local variables?
ANSWER
Static variables declared at block scope are initialized the first time control passes
through their declaration.
jobsiit.com
QUESTION 51
What do you mean by Modular Programming?
ANSWER
Modular programming is a software design technique that emphasizes separating the
functionality of a program into independent, interchangeable modules, such that each
contains everything necessary to execute only one aspect of the desired functionality.
jobsiit.com
QUESTION 52
What are Unions and what does it reflect in C?
ANSWER
Union is a user defined data type. In union, all members share the same memory
location.
For example in the following C program, both x and y share the same location.
jobsiit.com
QUESTION 53
What are the applications of Unions?
ANSWER
Unions can be useful in many situations where we want to use same memory for two
ore more members.
For example, suppose we want to implement a binary tree data structure where each
leaf node has a double data value, while each internal node has pointers to two
children, but no data.
jobsiit.com
QUESTION 54
What is the difference between Char a and Char a[1]?
ANSWER
char a represents a character variable and char a[1] represents a char array of size
1.
If we print value of char a, we get ASCII value of the character (if %d is used). And if we
print value of char a[1], we get address of the only element in array.
jobsiit.com
QUESTION 55
What do you understand by enumerations?
ANSWER
The process of allocating memory during program execution is called dynamic
memory allocation.
jobsiit.com
QUESTION 56
What are macros? What are the advantages and disadvantages of macros?
ANSWER
A macro is a way to automate a task or procedure which you perform on a regular basis.
Advantage: A large number of task or action can be recorded in a single macro
Disadvantage: If something needs to be changed in the macro, the whole macro must
be re-recorded
jobsiit.com
QUESTION 57
What are Arrays? Name the types of C arrays.
ANSWER
Array is a collection of variables belongings to the same data type. You can store group
of data of same data type in an array.
Types of C arrays:
One dimensional array
Multi dimensional array
jobsiit.com
QUESTION 58
What is typedef?
ANSWER
typedef is a keyword in the C and C++ programming languages.
The purpose of typedef is to form complex types from more-basic machine types and
assign simpler names to such combinations.
jobsiit.com
QUESTION 59
What is the difference between strings and arrays?
ANSWER
Array is a collection of variables belongings to the same data type. You can store group
of data of same data type in an array.
String is traditionally a sequence of characters, either as a literal constant or as some
kind of variable.
jobsiit.com
QUESTION 60
What is generic pointer in C?
ANSWER
When a variable is declared as being a pointer to type void it is known as a generic
pointer.
jobsiit.com
QUESTION 61
What do you understand by a function?
ANSWER
A function is a group of statements that together perform a task.
Every C program has at least one function, which is main(), and all the most trivial
programs can define additional functions.
jobsiit.com
QUESTION 62
What is hashing?
ANSWER
Hashing is the transformation of a string of characters into a usually shorter fixedlength value or key that represents the original string.
ANSWER
Techniques used for debugging:
Use compilers features
Read the fine module
Printf ( ) debugging
Code grinding
Assertion
jobsiit.com
jobsiit.com
QUESTION 64
Do you know pragma directive in C?
ANSWER
The Pragma directive is the method specified by the C standard for providing additional
information to the compiler, beyond what is conveyed in the language itself.
jobsiit.com
QUESTION 65
What is the output of printf(%d)?
ANSWER
When we write printf(%d) the compiler will print the value of x. But as there is nothing
after %d so compiler will show in output window garbage value.
jobsiit.com
QUESTION 66
Can include files be nested?
ANSWER
Yes. Include files can be nested any number of times. As long as you use precautionary
measures, you can avoid including the same file twice.
jobsiit.com
QUESTION 67
How many levels deep can include files be nested?
ANSWER
Even though there is no limit to the number of levels of nested include files you can
have, your compiler might run out of stack space while trying to include high number
of files.
This number varies according to your hardware configuration and possibly your
compiler.
jobsiit.com
QUESTION 68
What are compilers?
ANSWER
A compiler is a computer program that transforms source code written in
a programming language into another computer language (the target language, often
having a binary form known as object code).
jobsiit.com
QUESTION 69
What is #line used for?
ANSWER
#line lets you modify the compiler's line number and (optionally) the file name output
for errors and warnings.
jobsiit.com
QUESTION 70
What is the benefit of using enum to declare a constant?
ANSWER
The main benefit of using enum is that if you don't initialize your constants, each one
would have a unique value. The first would be zero and the rest would then count
upwards.
ANSWER
Sprintf() writes data to the character array.
Printf() writes data to the standard output device.
jobsiit.com
jobsiit.com
QUESTION 72
How can we reduce the file size of executable?
ANSWER
The file size of executable can be reduced with the help of dynamic linking for libraries.
jobsiit.com
QUESTION 73
What is a stack?
ANSWER
Stack is an area of memory that holds all local variables and parameters used by any
function, and remembers the order in which functions are called so that function
returns occur correctly.
ANSWER
Four types of stack in C are:
Block scope
Function scope
File scope
Program scope
jobsiit.com
jobsiit.com
QUESTION 75
Where are command line arguments given?
ANSWER
Command-line arguments are given after the name of a program in command-line
operating systems like DOS or Linux, and are passed in to the program from the
operating system.
jobsiit.com
QUESTION 76
What is nested structure?
ANSWER
Structure written inside another structure is called as nesting of two structures.
jobsiit.com
QUESTION 77
When should the volatile modifier be used?
ANSWER
The volatile modifier is a directive to the compilers optimizer that operations involving
this variable should not be optimized in certain ways.
jobsiit.com
QUESTION 78
What is a file header?
ANSWER
A header file is a file with extension .h which contains C function declarations and
macro definitions and to be shared between several source files.
There are two types of header files: the files that the programmer writes and the files
that come with your compiler.
jobsiit.com
QUESTION 79
What is Type casting?
ANSWER
Type casting is a way to convert a variable from one data type to another data
type. For example, if you want to store a long value into a simple integer then
you can type cast long to int.
jobsiit.com
QUESTION 80
What do you mean by Recursion and recursive call of the function?
ANSWER
Recursion is the process of repeating items in a self-similar way. Same applies in
programming languages as well where if a programming allows you to call a function
inside the same function that is called recursive call of the function as follows.
JobsIIT
Resources
http://www.cprogramming.com
http://ecomputernotes.com/what-is-c
http://www.tutorialspoint.com/cprogramming/
http://fresh2refresh.com/c
http://searchwindowsserver.techtarget.com/definition/C
http://www.studytonight.com/c
en.wikibooks.org/wiki/C_Programming/Variables
http://www.cprogramming.com/tutorial/c
http://www.learnconline.com
http://www.indiabix.com/technical/c/the-c-language-basics
http://ecomputernotes.com/what-is-c
http://www.programming-techniques.com