C Programming Interview Questions

C Programming Language Interview Questions

  1. Who is a developer of C programming language?

Ans . Dennis M Ritchie.

  1. When was c programming language developed?

Ans . C language was developed in 1972 at bell laboratories of AT&T.

  1. Which format specifier is used to print integer value?

Ans . %d

  1. Which format specifier is used to print character value?

Ans . %c

  1. Which format specifier is used to print floating point or decimal value?

Ans . %f

  1. Which format specifier is used to print string?

Ans . %s

  1. What are the types of storage classes available in c language?

Ans . There are 4 types of storage class:

  • automatic
  • external
  • static
  • register
  1. What is Local Variable in c

Ans . The variables declared inside the function are automatic or local variables.

The local variables exist only inside the function in which it is declared. When the function exits, the local variables are destroyed.

  1. What is Global Variable in c

Ans . Variables that are declared outside of all functions are known as external or global variables. They are accessible from any function inside the program.

  1. Which function is used to read the data from user in c?

Ans . scanf()

Example:

scanf(“%d”, &a);  // read the value of a

  1. Which function is used to print the data in c?

Ans . printf()

printf(“%d”, a);  // print the value of a

  1. What is array in c language?

Ans . Array is a homogeneous collection of data which is having a same datatype.

Syntax:

data_type array_name[size];

Example:

int a[10]     // create the integer array a with size of 10

  1. How to declare the string in c?

Ans . char s[10];  // declare the string s of character 10

  1. How to initialize strings in c?

Ans . char c[] = “xyzw”;

char c[50] = “xyzw”;

char c[] = {‘x’, ‘y’, ‘z’, ‘w’, ‘\0’};

char c[5] = {‘x’, y’, ‘z’, ‘w’, ‘\0’};

  1. How to read a string using scanf()?

Ans .

#include <stdio.h>

int main()

{

char str[20];

printf(“Enter str: “);

scanf(“%s”, str);

printf(“string  is %s.”, str);

return 0;

}

  1. What is the use of gets() and puts() function?

Ans .

gets() function is used to read a line of string.

puts() function is used to display the string.

Example is as follows,

#include <stdio.h>

int main()

{

char str[20];

printf(“Enter str: “);

gets(str);     // read string

printf(“str: “);

puts(name);    // display string

return 0;

}

  1. Write a program to explain the concept of string and pointer?

Ans .

#include <stdio.h>

int main(void) {

char name[] = “Nitin Shelke”;

printf(“%c”, *name);     // Output: N

printf(“%c”, *(name+1));   // Output: i

printf(“%c”, *(name+7));   // Output: e

char *namePtr;

namePtr = name;

printf(“%c”, *namePtr);     // Output: N

printf(“%c”, *(namePtr+1));   // Output: i

printf(“%c”, *(namePtr+7));   // Output: e

}

  1. Use of Strlen()

Ans . strlen() : used to find the length of the string

  1. Use of strrev()

Ans . strrev(): used to reverse the string

  1. Use of strcpy()

Ans . strcpy(): used to copy one string into another