C Programming Interview Questions With Answers - Part I.
1. Explain Various Classes Of Datatypes Of C?
Answer: Following are the major classes of data types in C language:
- Primary Data Types: Also, known as fundamental/basic data types. All C compilers support four basic data types namely: integer(int), character(char), floating(float), and double precision floating point (double). Then there are extended data types such as long int, double int.
- Derived Data Types: Also, known as secondary or user-defined data types. These data types, derived from basic data types, include arrays, pointer, structure, union, enum etc.
2. What Are Escape Sequences Characters? List Any Six Of Them.
Answer: The characters which when used with output functions like printf( ), putc(), put() etc. helps in formatting the output are known as Escape sequence character. The following is a list of six escape sequences.
- \n Newline
- \t Horizontal Tab
- \v Vertical Tab
- \b Backspace
- \r Carriage Return
- \\ Backslash
3. What Do You Mean By Underflow & Overflow Of Data?
Answer: When the value of the variable is either too long or too small for the data type to hold, the problem of data overflow or underflow occurs. The largest value that a variable can hold depends on the machine. Since floating point values are rounded off to the number of significant digits allowed, an overflow results in the largest possible real value whereas an underflow results in zero.
C does not provide any warning or indication of integer overflow; it simply gives erroneous result.
4. List Any Six Commonly Found Programming Errors In A C Program.
Answer: Six commonly found errors in a C program are:
- Missing or misplaced; or }, missing return type for a procedure, missing or duplicate variable declaration.
- Type mismatch between actual and formal parameters, type mismatch on assignment.
- Forgetting the precedence of operators, declaration of function parameters.
- Output errors means the program runs but produces an incorrect result. This indicates an error in the meaning of the program.
- Exceptions that include division by zero, null pointer and out of memory.
- Non-termination means the program does not terminate as expected, but continues running "forever."
5. Explain Divide & Conquer Strategy To Solve Any Problem.
Answer: The original problem is solved by repeatedly solving a divided sub-problem that is of smaller size and can be solved more efficiently. The problem is split into smaller sub-problems recursively until we eventually reach a stage where sub-problem is small enough to break further and can be solved easily. This strategy is called Divide and Conquer strategy.
Suppose a problem P is associated with a set S and an algorithm partitions S into smaller sets such that solution of the problem P is reduced to solution of its smaller sub-sets. Then this algorithm is called divide and conquer algorithm. For example, in searching for a key in an ordered list, the size of the list is halved after every search.
6. Differentiate Between White Box & Black Box Testing.
Answer: White box testing strategy deals with the internal logic and structure of the code. White box testing also known as glass, structural, open box or clear box testing, tests code written, branches, paths, statements and internal logic of the code etc. To implement white box testing, the tester must deal with the code and hence is needed to possess knowledge of coding and logic i.e. internal working of the code. White box test also needs the tester to consider the code and find out which unit/statement/chunk of the code is malfunctioning.
White box testing is applicable at unit, integration and system level however it is mainly done at unit level.
Black box testing Black-box test design treats the system as a "black-box", so it doesn't explicitly use knowledge of the internal structure. It takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object's internal structure.
This method of test design is applicable to all levels of software testing: unit, integration, functional testing, system and acceptance.
7. A Program Has Been Compiled & Linked Successfully. When You Run This Program, You Face One Or More Of The Following Situations
- Program Executed, But No Output
- It Produces Incorrect Answers
- It Does Not Stop Running.
What Are The Possible Causes In Each Case & What Steps Would You Take To Correct Them?
Answer: A program has been compiled and linked successfully.
- Program executed, but no output: This usually happens due to run time errors in the program like referencing an out-of-range array element or mismatch of data types.
- It produces incorrect answers: Then there may be logical errors in the program like failure to consider a particular condition or incorrect translation of the algorithm into the program or incorrect order of evaluation of statements etc.
- It does not stop running: This happens when we make use of correct syntax statement but incorrect logic like if(code=1) count++; Instead of using comparison operator we are using assignment which is syntactically correct so count++ is always executed resulting in infinite loop. Similar mistakes may occur in other control statements, such as for and while loop that causes infinite loops and does not stop running.
Check Out Other Questions:
6) What is scope & storage allocation of extern and global variables?
7) What is scope & storage allocation of register?
8) What is scope & storage allocation of static and local variables?
9) What is the difference between 'break' and 'continue' statements?
10) What is the difference between uses of 'FOR' and 'WHILE' loops?
11) Which bitwise operator is used for checking whether a particular bit is ON or OFF?
12) Which bitwise operator is used for turning OFF a particular bit in a number?
13) What is equivalent of multiplying an unsigned int by 2: left shift of number by 1 or right shift of number by 1?
14) What is Enumeration?
15) What is a structure?
...Return To C Questions INDEX.
...Return To C Programming INDEX.
... Return To HR Interview Index