C PROGRAMMING

What do you understand by calloc()?

calloc() is a dynamic memory allocation function that loads all the assigned memory locations with 0 value.

What happens when a header file is included with-in double quotes ““?

When a header file in c++ is included in double-quotes, the particular header file is f irst searched in the compiler’s current working directory. If not found, then the built-in include path is also searched.

Define <stdio.h>.

It is a header file in C that contains prototypes of functions such as scanf and printf.

What is the use of static functions.?

When we want to restrict access to functions, we need to make them static. Making functions static allows us to reuse the same function in C programming name in multiple files.

Name the four categories in which data types in the C programming language are divided in.

Basic data types – Arithmetic data types, further divided into integer and floating-point types

Derived datatypes –Arithmetic data types that define variables and assign discrete integer values only

Void data types – no value is available

Enumerated data types –Array types, pointer types, function, structure and union types

What is the function of s++ and ++s?

s++ is a single machine instruction used to increment the value of s by 1. (Post increment). ++s is used to carry out pre-increment.

What is the use of the ‘==’ symbol?

The ‘==’ symbol or “equivalent to” or “equal to” symbol is a relational operator, i.e., it is used to compare two values or variables.

What is the output of the following code snippet?

#include <stdio.h>

void local_static()

{

static int a;

printf(“%d “, a);

a= a + 1;

}

int main()

{

local_static();

local_static();

return 0;

}

      Answer:

 0 1

Mention some of the features of the C programming language.

Some of the feature are:

Middle-Level Language – Combined form of both high level language and assembly language

Pointers – Supports pointers

Extensible – Easy to add features to already written program

Recursion – Supports recursion making programs faster

Structured Language – It is a procedural and general purpose language. 

Name a ternary operator in the C programming language.

The conditional operator (?:)

Why is int known as a reserved word?

As int is a part of standard C language library, and it is not possible to use it for any other activity except its intended functionality, it is known as a reserved word.

What will this code snippet return?

void display(unsigned int n)

{

if(n > 0)

{

display(n-1);

printf(“%d “, n);

}

             }

        Answer:

Prints number from 1 to n.

Another frequent c interview question is what is meant by Call by reference?

When a variable’s value is sent as a parameter to a function, it is known as call by reference. The process can alter the value of the variable within the function. 

What information is given to the compiler while declaring a prototype function?

The following information is given while declaring a prototype function:

  •       Name of the function
  •       Parameters list of the function
  •       Return type of the function.[6] 
Why are objects declared as volatile are omitted from optimization?

This is because, at any time, the values of the objects can be changed by code outside the scope of the current code.

Give the equivalent FOR LOOP format.

a=0;

while (a<=10) 

{

printf (“%d\n”, a * a);

a++;

}

Answer:

for (a=0; a<=10; a++)

    printf (“%d\n”, a * a);

What is a modifier in the C programming language? Name the five available modifiers.

It is used as a prefix to primary data type to indicate the storage space allocation’s modification to a variable. The available modifiers are: 

  1. short
  2. long
  3. long long
  4. signed
  5. unsigned
A pointer *a points to a variable v. What can ‘v’ contain?

Pointers is a concept available in C and C++. The variable ‘v’ might contain the address of another memory or a value.

What three parameters fseek() function require to work after the file is opened by the fopen() function?

The number of bytes to search, the point of origin of the file, and a file pointer to the file.

Name a type of entry controlled and exit controlled loop in C programming.

Entry controlled loop- For loop (The condition is checked at the beginning)

Exit Controlled loop- do-while loop.[7]  (The condition is checked in the end, i.e. loop runs at least once)

Give the output of the following program:

 #include <stdio.h>

int main(void)

{

int arr[] = {20,40};

int *a = arr;

*a++;

printf(“arr[0] = %d, arr[1] = %d, *a = %d”,

arr[0], arr[1], *a);

return 0;

 Answer:

arr[0] = 20, arr[1] = 40, *p = 40

Explain Can if you can we free a block of memory that has been allocated previously? If yes, how?

A block of memory previously allocated can be freed by using free(). The memory can also be released if the pointer holding that memory address is: realloc(ptr,0).

How to declare a variable as a pointer to a function that takes a single character-pointer argument and returns a character?

char (*a) (char*);

What is the stack area?

The stack area is used to store arguments and local variables of a method. It stays in memory until the particular method is not terminated.

What is the function of the following statement?

sscanf(str, “%d”, &i);

To convert a string value to an integer value.

Will the value of ‘a’ and ‘b’ be identical or different? Why?

float num = 1.0;

int a = (int) num;

int b = * (int *) &num;

The variable stores a value of num that has been first cast to an integer pointer and then dereferenced. 

What are huge pointers?

Huge pointers are 32-bit pointers that can be accessed outside the segment, and the segment part can be modified, unlike far pointers.

What will be the output of the following?

#include<stdio.h>

main()

{

char *a = “abc”;

a[2] = ‘d’;

printf(“%c”, *a);

}

The program will crash as the pointer points to a constant string, and the program is trying to change its values.

What is a union?

A union is a data type used to store different types of data at the exact memory location. Only one member of a union is helpful at any given time.

How is import in Java different from #include in C?

Import is a keyword, but #include is a statement processed by pre-processor software. #include increases the size of the code.  

Enquire Now

Enquire Now

Enquire Now

Please Sign Up to Download

Please Sign Up to Download

Enquire Now

Please Sign Up to Download

Enquiry Form