Top

C Programming

11.

What is the use of printf() and scanf() functions?

Ans:

printf(): The printf() function is used to print the integer, character, float and string values on to the screen.

Following are the format specifier:

  • %d: It is a format specifier used to print an integer value.
  • %s: It is a format specifier used to print a string.
  • %c: It is a format specifier used to display a character value.
  • %f: It is a format specifier used to display a floating point value.
  • scanf(): The scanf() function is used to take input from the user.

12.

What is the use of the function in C?

Ans:

Uses of the C function are:

  • C functions are used to avoid the rewriting the same code again and again in our program.
  • C functions can be called any number of times from any place of our program.
  • When a program is divided into functions, then any part of our program can easily be tracked.
  • C functions provide the reusability concept, i.e., it breaks the big task into smaller tasks so that it makes the C program more understandable.

13.

What is the difference between call by value and call by reference in C?

Ans:

Following are the differences between a call by value and a call by reference are:

  Call by value Call by reference
Description When a copy of the value is passed to the function, then the original value is not modified. When a copy of the value is passed to the function, then the original value is modified.
Memory location Actual arguments and formal arguments are created in separate memory locations. Actual arguments and formal arguments are created in the same memory location.
Safety In this case, actual arguments remain safe as they cannot be modified. In this case, actual arguments are not reliable, as they are modified.
Arguments The copies of the actual arguments are passed to the formal arguments. The addresses of actual arguments are passed to their respective formal arguments.

 

14.

What is the differentiate between calloc() and malloc()?

Ans:

calloc() and malloc() are memory dynamic memory allocating functions. The only difference between them is that calloc() will load all the assigned memory locations with value 0 but malloc() will not.
 

  calloc() malloc()
Description The calloc() function allocates multiple blocks of requested memory. The malloc() function allocates a single block of requested memory.
Initialization It initializes the content of the memory to zero. t does not initialize the content of memory, so it carries the garbage value.
Number of arguments It consists of two arguments. It consists of only one argument.
Return value It returns a pointer pointing to the allocated memory. It returns a pointer pointing to the allocated memory.

 

15.

What is the differentiate between Actual Parameters and Formal Parameters?

Ans:

The Parameters which are sent from the main function to the subdivided function are called as Actual Parameters and the parameters which are declared a the Subdivided function end are called as Formal Parameters.

16.

Can a C program be compiled or executed in the absence of a main()?

Ans:

The program will be compiled but will not be executed. To execute any C program, main() is required.

17.

What is keyword auto for?

Ans:

By default every local variable of the function is automatic (auto). In the below function both the variables "i" and "j" are automatic variables.

void f() {
   int i;
   auto int j;
}

A global variable can’t be an automatic variable.

18.

What is a variable?

Ans:

A variable is the name storage.

19.

Can I declare the same variable name to the variables which have different scopes?

Ans:

Yes, Same variable name can be declared to the variables with different variable scopes as the following example.

int var;
void function() 
{ 
   int variable; 
}
int main() 
{ 
   int variable; 
}

 

20.

Which operator can be used to determine the size of a data type or variable?

Ans:

sizeof

Loading…
Tags: C Programming Interview Questions and Answers || C Programming Sort Questions and Answers || C Programming Detailed Questions and Answers || C Programming Tutorial