C Programming FAQ (Frequently Asked Questions and answers) for freshers

This post lists the C Programming FAQ (Frequently Asked Questions and answers) for freshers for next job interview or C Programming exam.

Dennis Ritchie

It was developed in 1972 at the bell laboratories of AT&T.

C is mid-level language and procedural language.

Most of the compiler and JVMs are written in C language.

  • Simple to learn as program parts can be broken into pieces.
  • It is portable. The one program can be run on any machine. 
  • It has a powerful set of data types and operators due to which works faster. 
  • It is a combination of both low-level language and high-level language.

Header files contain C functions declaration and macros. It is used with .h extension. 

Short, int, long, float, and double

The variable is a self-explanatory word meaning changing in value. 

Scope of the variable means where the variables are directly accessible. 

Variables that are declared inside a block of curly braces are known as local variables. These variables are accessible only inside the set of curly braces.

Variables that are declared in the program outside blocks and functions are known as global variables. These are accessible in the complete program are known as global variables.

A variable that is declared with a static keyword is known as a static variable. The scope of static variables is accessible only in the block of the set where it is declared.

Reserved Keywords are those words that have a predefined meaning in the language.

It is a built-in predefined function and macros that act as a directive to the compiler and it gets executed before the exact execution of the program.

Keywords, Constants, Strings, Operators, Identifiers, and special symbols used in C-language are known as Tokens. 

Loops are nothing but contain a set of statements that will execute again until the given condition is true.

There are three types of loops:

  • For loop: It is an open-ended loop. 
  • while loop: It is an entry control loop. 
  • do-while loop: It is an exit control loop. In the do-while loop, the set of statements will execute atleast once. 

An Array is a collection of elements of similar data types. The data type can be int, float, char, and double.

One-dimensional array: - It stores the element one after the other either in row or column.

Two-dimensional array: - It stores the element in the form of rows and columns. 

for(initialization; condition; increment/decrement operator)

Example: for(int i=0; i<5; i++){     

                  }

Static functions are those functions that are declared with the static keyword.

Jumping statements are those which interrupt the execution of the normal flow. There are two types of Jumping Statements. 

break statement: When a break statement is encountered inside the loop in the program the control will come out from the loop and continue with the statement followed by the loop. 

continue statement: When continue statement is encountered inside the loop. It will skip the statement after that and control goes back to the conditions stated.

The break statement can be used inside the loop and switch control statements.

The ‘/0’ is the symbol of the NULL character. It is used to notify the end of the string to the compiler. It is known as a terminating character.

The ‘/0’ is the symbol of the NULL character. It is used to notify the end of the string to the compiler. It is known as a terminating character.

++a is the prefix increment operator whose value is increased by 1 first then the operation is performed and a++ is the postfix increment operator whose value increased by 1 after the operation is performed.

‘=’ is an assignment operator which is used to assign the value in the variable and ‘==’ is a comparison operator which is used to check LHS is equal to RHS or not.

A nested loop means placing one more loop inside the loop. You can put run as many loops as you want. 

Yes, we can write a single line of code without { }. Curly braces are used to sum the several lines into one set.

The modulus operator gives the remainder of the division.

The pointer is nothing but a variable that refers to the address of the value.

The NULL pointer doesn’t refer to any value only NULL.

  • The size of the character is equal to 1 byte. 
  • The size of the integer is equal to 4 bytes. 
  • The size of the integer pointer and character pointer is 4 bytes and 8 bytes. 

Compound statements are made up of two or more program statements coupled to execute together.

In the case of a while statement, the condition is checked before the execution of inner statements. The execution stops if conditions turn out to be false. In the case of the do-while loop, once the set of the statement will execute then the condition in check.

  • We don’t need to write some set of lines again.
  • Functions provide the reusability of code.
  • It can be called from any part of the program.

return_type function_name(formal parameter lists)

     {

         function_body

     }

 

Call by Value

Call by Reference

We pass the copy of the values to the functions if there is no alteration in the original values. This is known as call by Value. 

We pass the copy of values to the functions, if original values are altered then it is known as call by reference.

The actual and formals arguments are stored in different memory locations

The actual and formal arguments are stored in the same memory location.

The pointer variable holds the address of another pointer variable which is holding the data value.

“Void” is used where we directly display the output from the function and returning any value to the called statement. In simple words, if you want to show the output from the function then use the void keyword.

The algorithm is a step-to-step procedure for writing a program. Before starting with a program, it is good practice to write steps so that we are aware of the program's execution.

scanf(“%d”,i)

In the above statement, we are taking the input from the user. An ampersand is placed before i variable. The correct syntax of taking an input is:

scanf(“%d”, &i);

When a function calls itself repeatedly until the provided condition comes out to be wrong is known as recursion. 

auto keyword refers to the automatic storage duration. The function’s local variables are by default auto. It is hardly used in programs.

No, we cannot declare global variables as automatic.

typedef keyword is used to simplify the complicated declaration of the type. We can say, it is used to alias the existing type.

A pointer pointing to the address location of the variable. Later, the variable is deleted from the location but still, the pointer is still pointing to the same location is known as Dangling Pointer.

The far pointer is that pointer that accesses the whole residency memory of RAM. It is a 32-bit pointer that obtains information outside the memory.

The memory is allocated during compile time in static memory allocation. We cannot increase the size during the execution of the program. It occupies so much memory as compare to dynamic memory allocation. Example: Array.

The memory is allocated during run time in the case of dynamic memory allocation. We can increase the size during the execution of the program. It occupies less memory as compared to static memory allocation.

Example: Linked list

A flowchart is a pictorial representation of step by step method of solving a problem. 

Modular programming means dividing the entire program into sub-programs to achieve the given task.

Actual parameters are those which are sent from the main function to the calling function.

Formal parameters are those parameters is defined in the brackets of the calling function.

printf(): It is used to print the output on the screen.

scanf(): It is used to take the input from the user.

getch(): It read characters from the keyboard and it does not use any buffer. It will not display any data on the screen.

getche(): It read characters from the keyboard and it uses a buffer. It will display the data on the screen.

rand() is used to generate random numbers.

void=10;

It is not a valid statement. “void” is a reserved word so we cannot use it as a variable name.

Yes, we can call one function inside another function as well. 

Dynamic memory allocation has three functions for allocating memory.

  • malloc():   ptr = (cast-type*) malloc(byte-size);
  • calloc():  ptr = (cast-type*)calloc(n, element-size);
  • realloc():  ptr = realloc(ptr, newsize);

American National Standards Institute.

To store the negative number, the following steps need to be followed.

step-1:- One’s complement of a positive number.

step-2:- Add 1 to above, one’s complement.

When the selection is based on a single expression or variable then prefer switch statement over if. The switch statement works commendably with integer and character data types.

When the variable is in use so much then the variable must be declared as a register. The CPU register will allocate the space for the variable so that we can operate on the variable easily.

The address of the initial value of the array is considered as the base address of the array.

Passing the arguments in the main() function during the program execution is known as the command-line argument.

Yes, the compilation is possible without main but we cannot execute the program.

The function will not print output on the console screen. sprint() refers to string print. It transfers the data to the buffer and returns a count of characters in the string.

The structure is user-defined data-type stores multiple values of different data types in a single unit. The members of the structure can be used accessed only with the structure variables. The different memory is allocated to each structure variable. 

The union is user-defined data-types store multiple values of different data types in a single unit. It doesn’t tenant the sum of the total memory of all members. It occupies the memory of the largest element only. It can access only one variable at a time because members are sharing the common space.

Yes, we can customize our own header file also. Put the functions inside the file you want to use and implement it with #include directive followed by the name of the file.

Run-time errors occur during the execution of the program.

Example of run-time error: when we are trying to divide any number by zero.

The newline space sequence is used to insert the new line. When the output is displaying on the screen the output move next line with the help of the newline space character inserted in the program.

strlen() is used to display calculate the length of the string.

Order of precedence table inform which operation must be performed in the operation and conditional statement.

The order of precedence table is as follow:

  • Unary operator
  • Arithmetic operator
  • Relational operator
  • Equality operator
  • Logical operator
  • Assignment operator