Question:1 to 20 Question:21 to 40
Question:41 to 60 Question:61 to 80
Question:81 to 100
Pagination with Rounded Borders
Question: #1) What are the key features in C programming language?
Machine Independent or Portable
Mid-level programming language
Structured programming language
Question: #2) What are the basic data types in C?
int – Represent number (integer)
float – Number with a fraction part.
double – Double-precision floating-point value
char – Single character
void – Special purpose type without any value.
Question: #3) What is the description for syntax errors?
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.
Question: #4) What do you understand by reserved words in a programming language?
Reserved words are special words.
These have a special for the compiler.
These are part of the standard C language library.
These should not be used as variable/identifiers if used as variables an error will get generated.
Example char, double, void, return, int, float, etc.
Question: #5) Please explain what is a header file in C? What will happen if we include a header file twice in a C program?
Header files store the definitions and set of rules governing different built-in functions of the C programming language. For instance, the printf() and scanf() functions are defined in the stdio.h header file.
Every header file contains a set of predefined functions, meant to make programming in C simpler. You need to include the specific header file in your C program to be able to use the functions defined in it. For example, you can’t use printf() and scanf() functions without including the stdio.h header file.
When a header file is included twice in a C program, the second one gets ignored. In actual, the #, called the include guard, preceding a header file ensures that it is included only once during the compilation process.
Question: #6) Please compare static memory allocation with dynamic memory allocation?
Following are the important differences between static and dynamic modes of memory allocation:
In dynamic memory allocation, memory can be increased while executing the program. This is not the case; however, with the static memory allocation where the option of increasing memory during program execution is not available.
Static memory allocation needs more memory space compared to dynamic memory allocation.
Arrays use static memory allocation while linked lists use dynamic memory allocation.
When does it happen?
Static memory allocation takes place at compile-time, while dynamic memory allocation happens at runtime.
Question: #7) Can you explain memory leak in C? Why should it be addressed?
Memory leak happens when a memory created in a heap remains undeleted. This can lead to additional memory usage and, thus, affect the performance of a program. This is exactly why the issue of memory leak must be addressed.
Question: #8) Please explain what do you understand by while(0) and while(1)?
while(0) means that the looping conditions will always be false, i.e., the code inside the while loop will not be executed. On the opposite, while(1) is an infinite loop. It runs continuously until coming across a break statement mentioned explicitly.
Note: Any non-zero integer inside the braces of the while loop will give an infinite loop. For example, while(-22) and while(24) will both yield an infinite loop.
Question: #9) State the difference between prefix increment and postfix increment.
In prefix increment, the value of the variable is incremented before the program execution. The variable is incremented post the program execution in postfix increment.
++a <- Prefix increment
a++ <- Postfix increment
Question: #10) Please explain the concept of Dangling Pointer in C? In how many ways can a pointer act as a Dangling Pointer?
A pointer that points to a memory location that is already deleted is called a dangling pointer. As per another definition, a dangling pointer is a pointer that points to a dereferenced memory location. A pointer acts as a dangling pointer in three cases:
Deallocation of memory
When the local variable isn’t static
When the variable goes out of scope
Initially, the dangling pointer holds a valid memory address. Later, however, the held address is released.
The Dangling Pointer Problem –
When A pointer is pointing to a memory location, and a B pointer deletes the memory occupied by the A pointer, then the A pointer still points to the memory location, which is no longer available. This is called the dangling pointer problem.
Question: #11) Is #include “stdio.h” correct? What’s the difference between using < > and ” ” for including the header file?
Yes, #include “stdio.h” is correct. The difference between using angle brackets (<>) and double quotes (” “) for including a header file is the way in which the compiler searches for the particular header file.
When we use angular brackets, the compiler searches for the header file only within the built-in include path. When, however, double quotes are used, the compiler searches for the header file first in the current working directory, and then in the built-in include path when not found in the current working directory.
Question: #12) How will you resolve the scope of a global symbol?
We can use the extern storage specifier for resolving the scope of a global symbol. The extern keyword is used for extending the visibility or scope of variables and functions. As C functions are visible throughout the program by default, its use with function declaration or definition is not required.
Question: #13) When do we use the register keyword?
The register storage specifier, i.e., the register keyword, is used for storing a variable in the machine register. This is typically used for heavily-used variables to the likes of a loop control variable. The main intent behind using the register keyword is to speed-up the program by minimizing variable access time.
Question: #14) What do you understand by rvalue and lvalue?
The expression on the left of the assignment operator (=) is called an lvalue. An rvalue is an expression on the right side of the assignment operator, and it is assigned to an ivalue.
int a = 25;
int a is the ivalue in the above-mentioned example while 25 is the rvalue. While an ivalue persists beyond a single expression, the rvalue doesn’t persist beyond the expression using it.
Question: #15) How are actual parameters different from formal parameters?
Actual parameters are the ones that are sent to the function at the calling end. Formal parameters, however, are the ones that are received during the function definition. A formal parameter is an identifier used in some function to stand for the value that is passed into the function by a caller. This actual value that is passed into the function by a caller is the actual parameter.
Formal parameters are bound to an actual value as long as their function is active. The formal parameters do not store any values when the function returns to its caller. For Example:
int totalsum(int a, int b, int c) // Formal parameters
total = a + b +c;
int a = 22; int m = 24; int p = 28; // Actual parameters
sum = totalsum(a, m, p);
printf (“The total sum is %d.”, sum);
The total sum is 74.
Another major distinction between actual parameters and formal parameters is that while the latter are always variables, the former can be expressions, function calls, or even numbers. For example, in the above example, the following are also valid actual parameters (in the function call to totalsum):
sum = totalsum (10+15, 12*2, 56/2); // Actual parameters are expressions.
sum = totalsum (a, (int) sqrt(576), p); // One of the actual parameters is a function call.
sum = totalsum (22, 24, 28); // Actual parameters are numbers.
Question: #16) Please explain a self-referential structure.
A self-referential structure contains the same structure pointer variable as its element. In other words, it is a data structure in which the pointer points to the structure of the same data type. A self-referential structure is used in Graphs, Heaps, Linked Lists, Trees, et cetera.
Question: #17) What do you understand by modular programming?
Modular approach to programming involves dividing an entire program into independent, interchangeable sub-programs, i.e., functions and modules for accomplishing the desired functionality. Each of the functions or modules involved in modular programming has everything required for executing a single aspect of the desired functionality of the entire program.
Question: #18) Please explain tokens in C.
Tokens are the smallest, indivisible units of a C program with distinct meanings. Following are the various types of tokens in C:
Constants – Fixed values that can’t be changed during the program execution.
Identifiers – This refers to the name of the functions, variables, arrays, structures, etc.
Keywords/Reserved Names – Predefined words with special meanings that can’t be used as variable names.
Operators – Symbols that tell the C compiler to perform specific logical, mathematical, or relational operations.
Special Characters – All characters excluding the alphabets and digits are special characters.
Question: #19) What do you understand by the C preprocessor?
The C compiler automatically uses the C preprocessor for transforming the program, i.e., performing certain things before the actual compilation starts. The C preprocessor is a macro processor because it enables defining brief abbreviations for longer constructs, called macros.
Question: #20) What are command line arguments in C?
Command line arguments are the parameters passed to the main() function in a C program during program execution. The typical use of command-line arguments is to fulfill the need of controlling the program from outside.
Observe the following code,
void main (int numofargs, char *args)
In the main() function, the count of the command line arguments is given out by the numofargs. The operating system updates it automatically. The args is a pointer array holding pointers of char type. These point to the (command line) arguments supplied to the program.
Note: When no command-line arguments are passed to the program, the numofargs parameter will be 1. args holds the name of the C program, args points to the first command-line argument, and args[n] points to the last command-line argument.
Class 11 (Python)
Class 12 (Python)
C Interview Questions
C++ Interview Questions