Top 40 C Programming Theory Questions and Answers
Top 40 C Programming Theory Questions and Answers
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.
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.
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
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.
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 >.
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.
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.
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.
In this example Name of the function is Sum, the return type is integer data type and it
accepts two integer parameters.
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.
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
For Loop
Do…While Loop
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.
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.
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.
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.
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.
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.
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
Signed
Unsigned
long long
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 –
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
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.
Ans) Dynamic data structure is more ef cient to the memory. The memory access occurs
as needed by the program.
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.
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?
As an error value.
As a sentinel value.
To terminate indirection in the recursive data structure.
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.
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