100% found this document useful (5 votes)
15K views

Top 40 C Programming Theory Questions and Answers

The document contains 24 questions and answers about C programming. Some key points covered include: - The main features of C like portability, modularity, flexibility and speed. - Basic data types in C like int, float, double, char and void. - Syntax errors occur due to mistakes in program syntax like incorrect commands or parameters. - Increment and decrement operators (++ and --) and how to perform increment/decrement. - Reserved words in C that have special predefined meanings. - Issues like dangling pointers, wild pointers, and the differences between operators like = and ==. - Functions, loops, pointers, header files, comments and more.

Uploaded by

Sahil Verma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
15K views

Top 40 C Programming Theory Questions and Answers

The document contains 24 questions and answers about C programming. Some key points covered include: - The main features of C like portability, modularity, flexibility and speed. - Basic data types in C like int, float, double, char and void. - Syntax errors occur due to mistakes in program syntax like incorrect commands or parameters. - Increment and decrement operators (++ and --) and how to perform increment/decrement. - Reserved words in C that have special predefined meanings. - Issues like dangling pointers, wild pointers, and the differences between operators like = and ==. - Functions, loops, pointers, header files, comments and more.

Uploaded by

Sahil Verma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

10/23/2018 Top 40 C Programming Interview Questions and Answers

Q #1) What are the key features in C programming language?

Portability – Platform independent language.


Modularity – Possibility to break down large programs into small modules.
Flexibility – The possibility to a programmer to control the language.
Speed – C comes with support for system programming and hence it is compiling
and executes with high speed when comparing with other high-level languages.
Extensibility – Possibility to add new features by the programmer.

Q #2) What are the basic data types associated with C?

Int – Represent number (integer)


Float – Number with a fraction part.
Double – Double-precision oating point value
Char – Single character
Void – Special purpose type without any value.

Q #3) What is the description for syntax errors?

Ans) The mistakes when creating a program called syntax errors. Misspelled commands or
incorrect case commands, an incorrect number of parameters when called a method
/function, data type mismatches can identify as common examples for syntax errors.

Q #4) What is the process to create increment and decrement stamen in C?

Ans) There are two possible methods to perform this task.

1) Use increment (++) and decrement (-) operator.

Example When x=4, x++ returns 5 and x- returns 3.

2) Use conventional + or – sign.

When x=4, use x+1 to get 5 and x-1 to get 3.

Q #5) What are reserved words with a programming language?

Ans) The words that are part of the slandered C language library are called reserved words.
Those reserved words have special meaning and it is not possible to use them for any
activity other than its intended functionality.

Example void, return, int.

Q #6) What is the explanation for the dangling pointer in C?

Ans) When there is a pointer with pointing to a memory address of any variable, but after

some time the variable was deleted from the memory location while keeping the pointer
pointing to that location.  Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 2/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Q #7) Describe static function with its usage?

Ans) A function, which has a function de nition pre xed with a static keyword is de ned
as a static function. The static function should call within the same source code.

Q #8) What is the difference between abs() and fabs() functions?

Ans) Both functions are to retrieve absolute value. abs() is for integer values and fabs() is
for oating type numbers. Prototype for abs() is under the library le < stdlib.h > and
fabs() is under < math.h >.

Q #9) Describe Wild Pointers in C?

Ans) Uninitialized pointers in the C code are known as Wild Pointers. These are a point to
some arbitrary memory location and can cause bad program behavior or program crash.

Q #10) What is the difference between ++a and a++?

Ans) ‘++a”  is called pre xed increment and the increment will happen rst on a variable.
‘a++’ is called post x increment and the increment happens after the value of a variable
used for the operations.

Q #11) Describe the difference between = and == symbols in C programming?

Ans) ‘==’ is the comparison operator which is use to compare the value or expression on
the left-hand side with the value or expression on the right-hand side.

‘=’ is the assignment operator which is use to assign the value of the right-hand side to
the variable on the left-hand side.

Q #12) What is the explanation for prototype function in C?

Prototype function is a declaration of a function with the following information to the


compiler.

Name of the function.


The return type of the function.
Parameters list of the function.

In this example Name of the function is Sum, the return type is integer data type and it
accepts two integer parameters.

Q #13) What is the explanation for cyclic nature of data types in C?



 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 3/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Ans) Some of the data types in C have special characteristic nature when a developer
assign value beyond the range of the data type. There will be no any compiler error and
the value change according to a cyclic order. This is called as cyclic nature and Char, int,
long int data types have this property. Further oat, double and long double data types do
not have this property.

This is called as cyclic nature and Char, int, long int data types have this property. Further
oat, double and long double data types do not have this property.

Q #14) Describe the header file and its usage in C programming?

Ans) The le contains the de nitions and prototypes of the functions being used in the
program are called a header le. It is also known as a library le.

Example– The header le contains commands like printf and scanf is the stdio.h.

Q #15) There is a practice in coding to keep some code blocks in comment symbols than
delete it when debugging. How this affect when debugging?

Ans) This concept called as commenting out and is the way to isolate some part of the
code which scans possible reason for the error. Also, this concept helps to save time
because if the code is not the reason for the issue it can simply uncomment.

Q #16) What are the general description for loop statement and available loop types in C?

Ans) A statement that allows executing statement or group of statements in repeated way
is de ned as a loop. Following diagram explains

Following diagram explains a general form of a loop.

There are 4 types of a loop statement in C.



While loop
 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 4/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

For Loop
Do…While Loop
Nested Loop

Q #17) What is a nested loop?

Ans) A loop running within another loop is referred as a nested loop. The rst loop is called
Outer loop and inside the loop is called Inner loop. Inner loop executes the number of
times de ne an outer loop.

Q #18) What is the general form of function in C?

Ans) Function definition in C contains four main sections.

Return Type -> Data type of the return value of the function.
Function Name -> The name of the function and it is important to have a meaningful
name that describes the activity of the function.
Parameters -> The input values for the function that need to use perform the
required action.
Function Body -> Collection of statement that needs to perform the required action.

Q #19) What is a pointer on a pointer in C programming language?

Ans) A pointer variable that contains the address of another pointer variable is called
pointer on a pointer. This concept de-refers twice to point to the data held by a pointer
variable.

In this example **y returns value of the variable a.

Q #20) What are the valid places to have keyword “Break”?

Ans) The purpose of the Break keyword is to bring the control out of the code block which
is executing. It can appear only in Looping or switch statements.

Q #21) What is the behavioral difference when include header file in double quotes (“”) and
angular braces (<>)?

Ans) When Header le include within double quotes (“”), compiler search rst in the

working directory for the particular header le. If not found then in the built in the include
 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 5/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

path. But when Header le include within angular braces (<>), the compiler only search in
the working directory for the particular header le.

Q #22) What is a sequential access file?

Ans) In general programs store data into les and retrieve existing data from les. With the
sequential access le such data saved in a sequential pattern. When retrieving data from
such les each data need to read one by one until required information nd.

Q #23) What is the method to save data in stack data structure type?

Ans) Data is stored in Stack data structure type using First in Last out (FILO) mechanism.
Only top of the stack is accessible at a given instance. Storing mechanism is referred as a
PUSH and retrieve is referred as a POP.

Q #24) What is the significance of C program algorithms?

Ans) The algorithm needs to create rst and it contains step by step guidelines on how
the solution should create. Also, it contains the steps to consider and the required
calculations/operations within the program.

Q #25) What is the correct code to have following output in C using nested for loop?

Q #26) Explain the use of function toupper() with and example code? 
 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 6/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Ans) Toupper() function is use to convert the value to uppercase when it uses with
characters.

Code –

Result –

Q #27) What is the code in while loop that returns the output of given code?


 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 7/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Q #28) What is the incorrect operator form following list(== , <> , >= , <=) and what is the
reason for the answer?

Ans) Incorrect operator is ‘<>’.This is the format correct when writing conditional
statements, but it is not a correct operation to indicate not equal in C programming and it
gives compilation error as follows.

Code –

Error –

Q #29) Is it possible to use curly brackets ({}) to enclose single line code in C program?

Ans) Yes, it is working without any error. Some programmers like to use this to organize
the code. But the main purpose of curly brackets is to group several lines of codes.

Q #30) Describe the modifier in C?

Ans) Modi er is a pre x to the basic data type which is used to indicate the modi cation
for storage space allocation to a variable.

Example– In 32-bit processor storage space for int data type is 4.When we use it with
modi er the storage space change as follows.

Long int -> Storage space is 8 bit


Short int -> Storage space is 2 bit

Q #31) What are the modifiers available in C programming language?

Ans) There are 5 modifiers available in C programming language as follows.



Short  Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 8/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Long
Signed
Unsigned
long long

Q #32) What is the process to generate random numbers in C programming language?

Ans) The command rand() is available to use for this purpose. The function returns any
integer number beginning from zero(0). Following sample code demonstrate the use of
rand().

Code –

Output –

Q #33) Describe newline escape sequence with a sample program?

Ans) New line escape sequence is represented by \n. This indicates the point that new line
need to start to the compiler and the output creates accordingly. Following sample
program demonstrate the use of newline escape sequence.

Code


 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 9/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Output screen

Q #34) Is that possible to store 32768 in an int data type variable?

Ans) Int data type only capable of storing values between – 32768 to 32767.To store 32768
a modi er needs to use with int data type. Long Int can use and also if there is no any
negative values unsigned int is also possible to use.

Q #35) Is there any possibility to create customized header file with C programming language?

Ans) It is possible and easy to create a new header le. Create a le with function
prototypes that needs to use inside the program. Include the le in ‘#include’ section from
its name.

Q #36) Describe dynamic data structure in C programming language?

Ans) Dynamic data structure is more ef cient to the memory. The memory access occurs
as needed by the program.

Q #37) Is that possible to add pointers to each other?

Ans) There is no possibility to add pointers together. Since pointer contains address
details there is no way to retrieve the value from this operation.

Q #38) What is indirection?

Ans) If you have de ned a pointer to a variable or any memory object, there is no direct
reference to the value of the variable. This is called indirect reference. But when we

declare a variable it has a direct reference to the value.
 Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 10/13
10/23/2018 Top 40 C Programming Interview Questions and Answers

Q #39) What are the ways to a null pointer can use in C programming language?

Ans) Null pointers are possible to use in three ways.

As an error value.
As a sentinel value.
To terminate indirection in the recursive data structure.

Q #40) What is the explanation for modular programming?

Ans) The process of dividing the main program into executable subsection is called
module programming. This concept promotes the reusability.

Conclusion
The questioner is based on the C programming language concepts including memory
management with pointers, the knowledge of its syntax and some example programs that
use Basic C program structure. Theatrical and practical knowledge of the candidate is
examined with the questions.

a Share 8 k Share 15 f +1 10 d Tweet 33


SHARES

FREE EBook Download!

Testing Help & Tutorials

QA Training
Selenium Tutorials
QTP Tutorials
ISTQB Study Guide
ISTQB Premium Study Guide
QC Tutorials
HP LoadRunner Tutorials
JMeter Tutorials
JIRA Tutorials
VBScript Tutorials
Best Test Management Tools
Appium Studio Tutorials

Unix Tutorials
Free DevOps Training  Menu
https://www.softwaretestinghelp.com/c-programming-interview-questions/ 11/13

You might also like