C Interview Questions and Answers for Freshers

Most Asked C Interview Questions

C Interview Questions and Answers are given on this page for technical interview preparation. You can practice most asked C Interview questions for freshers. We have covered C topics like Dangling Pointer, Preprocessor Directive, Dynamic Memory Allocation etc.

Page Highlights:

  • What is C?

  • Top 50 C Interview Questions.

  • Technical Interview Questions.

C Interview Questions and Answers

Introduction to C

C is a general purpose high-level language most popular amongst coders, it is the most compatible, easy to learn and effective programming language. It is a successor of B language that came out way back in the 70s and has been the most popular programming language ever since.

Use of C Language-

  • We can develop compilers in C language.
  • Network Drivers are also created using C language.
  • Text Editors are developed using the C language like Notepad++,gedit e.t.c.
  • Database Management System are developed using the C language like oracle database.

Top 50 C Interview Questions For Freshers

Ques 1: What is data type in C?

Ans. Data Type specifies the type of data that is assigned to a variable. Each variable used in the program will be associated with a datatype. Some mostly used datatypes are:

1.int:  

  • This datatype is used to store integers. 
  • It requires 4 bytes of memory.
  • Syntax : int i;
2.float:
  • This datatype is used to store decimal numbers with single precision.
  • It requires 4 bytes of memory.
  • Syntax : float i;
3.double:
  • This datatype is used to store decimal numbers with double precision.
  • It requires 8 bytes of memory.
  • Syntax : double i;
4.char:
  • This datatype is used to store a single character.
  • It requires 1 byte of memory.
  • Syntax: char a;
C interview question and answers

Ques 2: What is heap in C?

Ans.

In C, the “heap” is a region of memory used for dynamic memory allocation at runtime. It allows you to allocate and deallocate memory as needed using functions like malloc and free. Unlike the stack, the heap provides unstructured storage and requires manual memory management.

Ques 3 : What is the diffrence between local variable and global variable?

Ans.

Local variables: The variables that are defined within the function and are accessible to that function itself are known as “local variables”.

Example :
#include <stdio.h>

void main(){

int c = 3;
printf(“%d”,c);

}

Global variables: The variables that are defined outside the function block and are accessible to any function are known as “global variables”.

Example :
#include <stdio.h>
int c = 3;


void main(){


printf(“%d”,c);

}

Ques 4: Which one is better to use malloc() or calloc()?

Ans.

Use malloc() when you need to allocate memory but don’t require it to be initialized to any specific value, Use calloc() when you want to allocate memory and initialize it to zero. 

Neither  is inherently “better” than the other; it depends on your use case:

Ques 5: Explain about ++var and var ++.

Ans. ++e is called pre-increment and e++ is called post-increment. Pre-increment means before assigning the value to a variable, the value will be incremented by one. Whereas Post-increment means after assigning the value to a variable, the value is incremented by one.

Example:

#include <stdio.h>
int main(){

     int e = 2;

     printf("%d\t",var++);

     printf("%d\t",e);

     printf("%d\t",++var);

     printf("%d\t",e);

     return 0;

}

Output : 2 3 4 4

Ques 6: What are the valid places to use the keyword break?

Ans. In C, you can use the break keyword in the following valid places:
Inside a loop to exit the loop prematurely based on a condition.
Inside a switch statement to exit the switch block.
Inside nested loops to exit the innermost loop.

Ques 7: Give an example for ternary operator in C.

Ans. “?:” is known as ternary operator or conditional operator. It is similar to if else control flow. And also it takes less space.

Syntax: result = condition ? ValueReturnedIfTrue : ValueReturnedIfFalse
Example:
#include <stdio.h>
int main(){

    int a = 2,b = 3;

    a>b?printf("a is greatest number"):printf("b is greatest number");

     return 0;

}

Output: b is greatest number

Ques 8 : When should a far pointer be used?

Ans.

Far pointers are rarely used in modern programming. They were more relevant in older systems and specialized scenarios like real-mode programming in early x86 processors, MS-DOS programming, low-level system programming, and embedded systems.

Ques 9 : Differentiate between constant and variable in C.

Ans.
  • Constant : It is an identifier whose value is constant that can’t be changed.
Syntax : const float f = 5.69; In the above one, the value of f can’t be changed, it is fixed throughout the program.
  •  Variable : It is an identifier whose value can be changed in the program, it is not fixed as constant.
Syntax : float f = 5.69; In the above one, the value of f can be changed in the program, it isn’t fixed throughout the program.

Ques 10 : Explain about a dangling pointer?

Ans. A dangling pointer is a pointer which points to some memory location that has been deleted or freed already. In simpler words, Any pointer pointing to a destroyed object or which does not contain a valid address is called a dangling pointer. If any pointer points to a memory address of a variable, after some time if the variable is deleted from memory but still if the pointer points to the same address location, it is a dangling pointer.

Example:
#include <stdio.h>

#include <stdlib.h> void main() {      int *p = (int *)malloc(sizeof(int));      // After below free call, ptr becomes a       // dangling pointer      free(p);     }

Ques 11 : Is it necessary to have a main() function in a C program?

Ans. Yes, to execute the program, the main() function is important. The program won’t get executed without that function.

Ques 12 : When Would You Use A Pointer To A Function?

Ans.

A pointer to a function is a variable that stores the memory address of a function. It allows you to indirectly call the function it points to, making it possible to dynamically select and execute different functions at runtime or use them in various advanced programming scenarios, such as callbacks, function tables, and dynamic behavior modification.

C interview question and answers

Ques 13 : What are preprocessor directives in C?

Ans. 

In C, built-in predefined functions or macros are referred to as preprocessor directives because they give the compiler instructions before the program is actually run. The process of writing and running a C program involves many steps. Macros, File Inclusion, Conditional Compilation, and other directives like #undef and #pragma are the main categories of preprocessor directives.

Example :
#include <stdio.h> //preprocessor directive
 
#define END 5 //preprocessor directive

int main(){

for (int i = 0; i < END+1; i++) {

printf("%d \n",i);

}

return 0;

}
preprocessor in c

Ques 14 : What are tokens in C?

Ans. 

In C programming, “tokens” are the smallest units of source code recognized by the compiler. They include:
Keywords: Reserved words with predefined meanings (e.g., if, int).
Identifiers: User-defined names for variables, functions, etc.
Constants: Fixed values (e.g., 42, “Hello”).
String Literals: Sequences of characters in double quotes.
Operators: Symbols for operations (e.g., +, ==).
Punctuation: Structural symbols like ; and ,.
Comments: Explanatory notes for programmers.
Preprocessor Directives: Commands for the preprocessor (e.g., #include).

Ques 15 : Why is C a Middle level Language?

Ans. A middle level language is one that binds the gap between machine level language and high level language. C language is one such programming language.  It finds its application in both, system programming (like as operating system) as well as application programming (like as spreadsheet). Middle level languages are more related to machine as well as human language. So that’s why it is called “Middle level language”.

Ques 16 : What are the key features in the C programming language?

Ans. Key features of C  are as follows:

  • Portability: C language has no dependency on the platform.
  • Modularity: Scope of breaking bigger programs to smaller reusable modules.
  • Flexibility: The possibility of a programmer to control the language.
  • Speed: C compiles and executes with high speed when compared with other high-level languages as it comes with support for system programming and hence it .
  • Extensibility: Possibility to add new features by the programmer.

Ques 17 : What are header files and their uses?

Ans.

Header files in programming contain declarations of functions, variables, and types used in a program. They promote modularity, prevent code duplication, and enable integration with libraries. They are included in source code files to provide information to the compiler about a program’s interface

Ques 18: How will you print “Hello World” without a semicolon?

Ans.
#include <stdio.h> 

int main(void){

if(printf("Hello World")){

}

}

Ques 19: Why is C called mother of all languages?

Ans. Many core concepts and data structures like arrays, lists, functions, strings, etc. were introduced through C Language. Many of the new programming languages have been developed on the basic concepts of C Language.

Ques 20: How do you Print An Address?

Ans. Using the %P specification in the printf() or( fprintf() or sprintf() ) statement. This prints a void pointer (void*). This format might change from compiler to compiler.  If you have some other kind of pointer (not a void*) and you want to be very safe, cast the pointer to a void*: printf (“%Pn”, (void*) buffer);

C Programming Language Interview Questions

Ques 21:What is the equivalent code of the following statement in WHILE LOOP format? for (int a=1; a<=100; a++) printf ("%d\n", a * a);

Ans.
int a=1;
while (a<=100) {
printf ("%d\n", a * a);
a++;
}
 

Ques 22: What are loops and how can we create an infinite loop in C?

Ans.

Loops are programming constructs that allow you to execute a block of code repeatedly as long as a certain condition is met. They are essential for automating repetitive tasks and controlling the flow of a program.

Infinite loops in C are those that run endlessly without a way to exit. You can create them intentionally (e.g., for continuous program execution) or unintentionally (e.g., due to coding errors).

Ques 23: What are entry controlled loop and exit controlled loop?

Ans. Entry-controlled and exit-controlled loops are two common types of loops used in programming. They differ in how they evaluate the loop condition and when they decide to repeat or terminate the loop:

Ques 24: What is the difference between type casting and type conversion?

Ans.

AspectType castingType conversion
Syntax and Language FeaturesSimpler and more consistent syntaxMore complex syntax with features like operator overloading and pointers
Memory ManagementAutomatic memory management (garbage collection)Manual memory management using new and delete
Platform IndependencePlatform-independent through JVMPlatform-dependent, requires recompilation for different platforms
CompilationCompiled to bytecode, executed by JVMCompiled directly to machine code for the target platform
Standard LibrariesComprehensive Java Standard LibraryRich C++ Standard Library including STL for data structures and algorithms

Ques 25: How is the null pointer different from a void pointer?

Ans.

A null pointer is basically a null value assigned to a pointer of any data type whereas a void pointer is a data type which remains void as long as an address of a data type is not assigned to it.The data type of the pointer is nothing but the type of data stored at the memory location where the pointer is pointed. When you are not sure about the type of data that is going to be stored at a particular memory location, you need to create the void pointer.Null pointer does not contain a reference to any variable/value. Hence we may state that it has a NULL as its value making it a null pointer.void pointer is always of type void *

#include<stdio.h>
 #include<stdlib.h> 
void main(){

    int a = 22;

    int *notnullpointer = &a;

    int *nullpointer1;                             
    int *nullpointer2 = 0;                                              
    if (notnullpointer == 0) printf ("\nNot null pointer is null.");

    else printf ("\nNot null pointer is not null.");

    if (nullpointer1 == 0) printf ("\nNull pointer 1 is null.");

    else printf ("\nNull pointer 1 is not null.");

    if (nullpointer2 == 0) printf ("\nNull pointer 2 is null.");

    else printf ("\nNull pointer 2 is not null.");

    printf ("\nNot null pointer has stored the address %d.", &notnullpointer);

    printf ("\nNull pointer 1 has no valid address.");

    printf ("\nNull pointer 2 has no valid address.");

Ques 26: What is a sequential access file?

Ans. In this type of file, data is kept in sequential order if we want to read the last record of the file, we need to read all records before that record so it takes more time. When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.

Ques 27: Compare arrays with pointers in the C programming language?

Ans. Following are the various differences between arrays and pointers in C:
  • Definition – A pointer is a variable that stores or points to the memory address of some other variable whereas an array is a form of data structure that stores multiple, homogeneous elements at contiguous memory locations.
  • Initialization – An array can be initialized at the definition whereas the pointer can’t be done in the same way.
  • Size – an array is capable of storing multiple elements whereas a pointer can store the address of only a single variable. The total number of elements stored by arrays is determined by the array size.

Ques 28: What is the difference between call by value and call by reference ?

Ans.

Call by Value:
Copies the value of the argument into the function parameter.
Changes to the parameter inside the function do not affect the original argument.
Call by Reference:
Passes a reference (memory address) of the argument into the function.
Changes to the parameter inside the function directly affect the original argument.
Code for call by value:

#include<stdio.h>
void swapx(int a, int b);
int main()
{
int x = 10, y = 20;
swapx(x, y);
printf("In the Caller:\nx = %d y = %d\n", x, y);
return 0;
}
void swapx(int a, int b)
int t;
t = a;
a = b;
b = t;
printf("Inside Function:\nx = %d y = %d\n", a, b);
}

Code for call by reference

#include<stdio.h>
void callByReference(int *num) {
(*num)++;
}
int main() {
int x = 5;
printf("Original value of x: %d\n", x);
callByReference(&x);
printf("Modified value of x: %d\n", x);
return 0;

Ques 29 :What are enumerations?

Ans.

In C, enumerations (or enums) are user-defined data types. Enumerations allow integral constants to be named, which makes a program easier to read and maintain. For example, the days of the week can be defined as an enumeration and can be used anywhere in the program.

Ques 30: List out some of the C compilers.

Ans.

C programming is a very old programming language and has a wide range of compilers available in the market. They are available in multiple operating systems. Some of them are listed below

  • AMPC
  • CCS C Compiler
  • ch
  • clang
  • Cygwin
  • Digital mars
  • GCC compiler
  • MikroC Compiler
  • Portable C Compiler, Power C, QuickC, Ritchie C Compiler, Small-C

Ques 31: What is recursion in C?

Ans.

In some special cases, a function can call itself and this process is called recursion. In this process, this function is called a Recursive function. Recursive function comes in two phases:

  1. Winding phase
  2. Unwinding phase
Winding phase: When the recursive function calls itself, and this phase ends when the condition is reached.
Unwinding phase: Unwinding phase starts when the condition is reached, and the control returns to the original call.
#include <stdio.h>
int calculate_fact(int);

int main(){

int n=5,f;

f=calculate_fact(n); // calling a function

printf("factorial of a number is %d",f);

return 0;

}

int calculate_fact(int a){

if(a==1){

return 1;

}

else

return a*calculate_fact(a-1); //calling a function recursively.

}

Ques 32 : Write a C program to print the Fibonacci series using recursion and without using recursion.

#include 

int main() {
int n, i;
long long int a = 0, b = 1, nextTerm;

printf("Enter the number of terms: ");
scanf("%d", &n);

printf("Fibonacci Series up to %d terms:\n", n);

for (i = 1; i <= n; i++) {
if (i == 1) {
printf("%lld, ", a);
continue;
}
if (i == 2) {
printf("%lld, ", b);
continue;
}
nextTerm = a + b;
a = b;
b = nextTerm;
printf("%lld, ", nextTerm);
}

printf("\n");

return 0;
C interview question and answers

Ques 33 :What is Dynamic Memory allocation? Mention the syntax.

Ans. Allocating memory to the program and its variables in runtime is the process of Dynamic Memory Allocation.The dynamic Memory Allocation process involves three functions for allocating memory and one function to free the used memory.
  • malloc() Syntax : ptr = (cast-type*) malloc(byte-size);     –   Allocates memory.
  • calloc() Syntax : ptr = (cast-type*)calloc(n, element-size);  –    Allocates memory.
  • realloc() Syntax: ptr = realloc(ptr, newsize);  –    Allocates memory.
  • free () Syntax: free(ptr)      –    Deallocates memory.

Ques 34 : How to convert a Number to a String?

Ans.

There are a number of functions to convert numbers to many from one format to another. Some of the functions are listed below:

Function Name Purpose :

  • iota():    Converts an integer value to a string.
  • ltoa ():   Converts a long integer value to a string.
  • ultoa (): Converts an unsigned long integer value to a string.

The following functions can be used to convert floating-point values to strings:

Function Name Purpose :

  • ecvt():   Converts a double-precision floating-point value to a string without an embedded decimal point.
  • fcvt(): Same as ecvt(), but forces the precision to a specified number of digits.
  • gcvt(): Converts a double-precision floating-point value to a string with an embedded decimal point.
  • strtod(): Converts a string to a double-precision floating-point value and reports any “leftover” numbers that could not be converted.
  • strtol(): Converts a string to a long integer and reports any “leftover” numbers that could not be converted.
  • strtoul(): Converts a string to an unsigned long integer and reports any “leftover” numbers that could not be converted.

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

Ans. printf(): This function helps in printing the integer, character, float, and strings.

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 helps in obtaining the input from the user.

Ques 36 : What is the use of a static variable in C?

Ans. A static variable is used for a common value which is shared by all the methods and its scope is till the lifetime of the whole program. In the C programming language, static is used with global variables and functions to set their scope to the containing file.

Following are some more properties of a static variable:

  • The static variable retains its value between multiple function calls.
  • Static variables are used because the scope of the static variable is available in the entire program. So, we can access a static variable anywhere in the program.
  • The static variable is initially initialized to zero. If we update the value of a variable, then the updated value is assigned.
  • The static variable is used as a common value that is shared by all the methods.
  • The static variable is initialized only once in the memory heap to reduce memory usage.

Ques 37 : Can you tell me how to check whether a linked list is circular?

Ans. Create two pointers, and set both to the start of the list. Update each as follows:

while (pointer1) {
pointer1 = pointer1->next;
 
pointer2 = pointer2->next;
 
if (pointer2) pointer2=pointer2->next;
 
if (pointer1 == pointer2) {
 
print ("circular");
 
}}
If a list is circular, at some point pointer2 will wrap around and be either at the item just before pointer1, or the item before that. Either way, it’s either 1 or 2 jumps until they meet.

Ques 38 : Write a C program to swap two numbers without using a third variable.

#include 


int main() {
    int num1, num2;


    printf("Enter two numbers: ");
    scanf("%d %d", &num1, &num2);


    printf("Before swapping: num1 = %d, num2 = %d\n", num1, num2);


    // Swap the numbers without using a third variable
    num1 = num1 + num2;
    num2 = num1 - num2;
    num1 = num1 - num2;


    printf("After swapping: num1 = %d, num2 = %d\n", num1, num2);


    return 0;
}
						

Ques 39 : Write a code to generate random numbers in C Language

Ans. Random numbers in C Language can be generated as follows:

#include 
#include 
int main()
{
int a,b;
for(a=1;a<=10;a++)
{
b=rand();
printf("%dn",b);
}
return 0;
}
OUTPUT
1987384758
2057844389
3475398489
2247357398
1435983905

Also Check Out:-

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

C Coding Interview Questions

Ques 40 : Write a program to check whether a string is a palindrome or not.

#include 
#include 


// Palindrome function to check
// whether a string is palindrome
// or not
void Palindrome(char s[])
{
	// Start will start from 0th index
	// and end will start from length-1
	int start = 0;
	int end = strlen(s) - 1;


	// Comparing characters until they
	// are same
	while (end > start) {
		if (s[start++] != s[end--]) {
			printf("%s is not a Palindrome \n", s);
			return;
		}
	}
	printf("%s is a Palindrome \n", s);
}


// Driver code
int main()
{
	Palindrome("abba");
	return 0;
}




						

Ques 41 : What do you mean by Memory Leak?

Ans. Memory Leak occurs when a programmer allocates dynamic memory to a program but fails to free or erase the used memory after the code has been completed. If daemons and servers are included in the software, this is dangerous.

#include 
#include 
int main()
{
int* ptr;
int n, i, sum = 0;
n = 5;
printf("Enter the number of elements: %dn", n);
ptr = (int*)malloc(n * sizeof(int));
if (ptr == NULL)
{
printf("Memory not allocated.n");
exit(0);
}
else
{
printf("Memory successfully allocated using malloc.n");
for (i = 0; i<= n; ++i)
{
ptr[i] = i + 1;
}
printf("The elements of the array are: ");
for (i = 0; i<=n; ++i)
{
printf("%d, ", ptr[i]);
}
}
return 0;
}
OUTPUT
Enter the number of elements: 5
Memory successfully allocated using malloc.
The elements of the array are: 1, 2, 3, 4, 5

Ques 42 : Explain Local Static Variables and what is their use?

Ans. A local static variable is one whose existence does not end when it is declared in a function call. It is valid for the duration of the entire curriculum. The function’s calls all share the same copy of local static variables.

#include <stdio.h>
void fun() 
{ 
static int x; 
printf("%d ", x); 
x = x + 1; 
} 
int main() 
{ 
fun(); 
fun(); 
return 0; 
}

Ques 43 : How can you remove duplicates in an array?

Ans. The following program will help you to remove duplicates from an array.

#include 
int main()
{
int n, a[100], b[100], calc = 0, i, j,count;
printf("Enter no. of elements in array");
scanf("%d", &n);
printf("Enter %d integersn", n);
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i< n; i++) 
{
for (j = 0; j< calc; j++) 
{
if(a[i] == b[j])
break; 
}
if (j== calc)
{
b[count] = a[i];
calc++; 
}
}
printf("Array obtained after removing duplicate elementsn");
for (i = 0; i< calc; i++)
{ 
printf("%dn", b[i]);
}
return 0;
}
OUTPUT:-
Enter no. of elements in array. 5
Enter 5 integers
12
11
11
10
4
Array obtained after removing duplicate elements
12
11
10
4

Ques 44 : Write a program to print the factorial of a given number with the help of recursion.

#include
// Function to calculate the factorial of a number using recursion
unsigned long long factorial(int n) {
if (n == 0 || n == 1) {
return 1; // Base case: factorial of 0 and 1 is 1
} else {
return n * factorial(n - 1); // Recursive case
}
}

int main() {
int num;

printf("Enter a non-negative integer: ");
scanf("%d", &num);

if (num < 0) {
printf("Factorial is not defined for negative numbers.\n");
} else {
unsigned long long fact = factorial(num);
printf("Factorial of %d = %llu\n", num, fact);
}

return 0;
}
C interview question and answers

Ques 45 :What is file operation in c?

File operations in C involve reading from and writing to files on a computer’s storage system. The Standard Input/Output Library (stdio.h) provides a set of functions for performing file operations.
Opening a File:
fopen(): Opens a file and returns a file pointer that allows you to read from or write to the file.
Closing a File:
fclose(): Closes an opened file to free up system resources.
Reading from a File:
fscanf(): Reads formatted data from a file.
Writing to a File:
fprintf(): Writes formatted data to a file.
fputs(): Writes a string to a file.

Ques 46 : Write a program to merge two sorted linked list?

#include
#include

// Define a structure for a singly linked list node
struct Node {
int data;
struct Node* next;
};

// Function to insert a new node at the end of a linked list
struct Node* insertNode(struct Node* head, int data) {
struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
newNode->data = data;
newNode->next = NULL;

if (head == NULL) {
head = newNode;
} else {
struct Node* current = head;
while (current->next != NULL) {
current = current->next;
}
current->next = newNode;
}

return head;
}

// Function to merge two sorted linked lists
struct Node* mergeSortedLists(struct Node* list1, struct Node* list2) {
struct Node* mergedList = NULL;
struct Node* current1 = list1;
struct Node* current2 = list2;

while (current1 != NULL && current2 != NULL) {
if (current1->data <= current2->data) {
mergedList = insertNode(mergedList, current1->data);
current1 = current1->next;
} else {
mergedList = insertNode(mergedList, current2->data);
current2 = current2->next;
}
}

// If one list is exhausted, append the remaining elements of the other list
while (current1 != NULL) {
mergedList = insertNode(mergedList, current1->data);
current1 = current1->next;
}

while (current2 != NULL) {
mergedList = insertNode(mergedList, current2->data);
current2 = current2->next;
}

return mergedList;
}

// Function to print a linked list
void printList(struct Node* head) {
struct Node* current = head;
while (current != NULL) {
printf("%d -> ", current->data);
current = current->next;
}
printf("NULL\n");
}

int main() {
struct Node* list1 = NULL;
struct Node* list2 = NULL;

// Insert elements into the first sorted linked list
list1 = insertNode(list1, 1);
list1 = insertNode(list1, 3);
list1 = insertNode(list1, 5);

// Insert elements into the second sorted linked list
list2 = insertNode(list2, 2);
list2 = insertNode(list2, 4);
list2 = insertNode(list2, 6);

printf("First sorted linked list: ");
printList(list1);

printf("Second sorted linked list: ");
printList(list2);

// Merge the two sorted linked lists
struct Node* mergedList = mergeSortedLists(list1, list2);

printf("Merged sorted linked list: ");
printList(mergedList);

return 0;
}						
C interview question and answers

Ques 47: What are rvalue and lvalue?

Ans. In an assignment, an lvalue is the left side operant, while a rvalue is a right. You can also remember lvalue as a place. As a result, lvalue refers to a place where any value can be stored. For example, in the statement I = 20, the value 20 is to be stored in the variable i’s position or address. Rvalue is 20 in this case. Then the argument 20 = I is invalid. As 20 does not reflect any position, it will result in the compilation error “lvalue needed.”

Ques 48: What is the difference between void foo(void) and void foo()?

Ans. In C, void foo() denotes a function that takes an unspecified number of unspecified type arguments, while void foo(void) denotes a function that takes no arguments. In the case of void foo(), the compiler will not raise any errors if we call it foo(1,2,3). In the case of void foo, however, the compiler will generate an error (void). When calling a function in C, the caller moves all of the arguments into the stack in reverse order before calling the callee. The compiler will not evaluate the arguments passed to foo if you use foo(). In the case of foo(void), the compiler will check the number of arguments before calling the function and will raise an error if the number of arguments is incorrect.

Ques 49: Differentiate between getch() and getche().

Ans. The only difference between the two roles is that one reads characters from the keyboard and the other does not.

getch() is a function that reads characters from the keyboard without using any buffers. As a result, no data is shown on the computer.

getche() uses a buffer to read characters from the keyboard. As a result, information is shown on the projector.

#include <stdio.h>
#include <stdlib.h>
int main()
{
char ch;
printf("Please enter a character ");
ch=getch();
printf("nYour entered character is %c",ch);
printf("nPlease enter another character ");
ch=getche();
printf("nYour new character is %c",ch);
return 0;
}
Output
 
Please enter a character
Your entered character is x
Please enter another character z
Your new character is z

Ques 50: Can I use int datatype to store 32768 value?

Ans. No, the Integer data type does not support the range -32768 to 32767. Any value greater than that would be discarded. We have the choice of using float or long int.

Also Check:

FAQs on C Interview Questions

Name some types of searching.

Ans. Linear Search, Binary Search.

Name some types of sorting.

Ans. Quick Sort, Merge Sort, Radix Sort, Bubble Sort, Heap Sort.

One comment on “C Interview Questions and Answers for Freshers”


  • SANJAY.

    #include “stdio.h”
    int main()
    {
    int charmander, charmeleon = 5, charizard = 5;
    charmander = charmeleon == charizard;
    printf(“%d”, charmander);
    return 0;
    }