C Programming for Computer Science and IT

C programming concepts for GATE exam preparation covering arrays, functions, loops, and data types

15 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

An array is created to store the salary of some employees. There are 10 elements in the array, but elements of array cannot be initialized. What type of array is this?

  1. Automatic
  2. Static
  3. External
  4. Both automatic & external
  5. None of these
Question 2 Multiple Choice (Single Answer)

An array is created to store some data. The data type of the array is declared as “long” data type. What will be size of array (in bytes) if we assume that it contains only 10 elements?

  1. 20 bytes
  2. 40 bytes
  3. 10 bytes
  4. 80 bytes
Question 3 Multiple Choice (Single Answer)

Which of the following statements is/are true for an array?
(1) The element number in an array plays a major role in calling each element.
(2) All elements of an array share the same name.
(3) Any particular element of an array cannot be modified separately without disturbing others.

  1. Only (1)
  2. Only (2)
  3. Only (3)
  4. Both (1) & (2)
  5. Both (2) & (3)
Question 4 Multiple Choice (Single Answer)

What would be the output of the following program?
#include<stdio.h>
#include<conio.h>
int rec(int);
int main()
{
int a=5;
int flop;
flop=rec(a);
printf(answer=%d,flop);
getch();
}
int rec(int x)
{
int p;
if(x==1)
return 1;
else
{
p=x*rec(x-1);
return p;
}

}
  1. 140
  2. 120
  3. 100
  4. Error in program
  5. None of these
Question 5 Multiple Choice (Single Answer)

Which of the following statements is/are true?
(1)Function declaration specifies the return type of function and types of parameters it will accept.
(2)Variable declared in a function is also available for the other functions.
(3) Function definition defines the task of main program.

  1. Only (1)
  2. Only (2)
  3. Only (3)
  4. Both (1) & (2)
  5. Both (2) & (3)
Question 6 Multiple Choice (Single Answer)

What is the difference between “while loop” and “do while loop”?

  1. We put a semicolon in “while loop” after the while expression as in while(expression); , but semicolon is not allowed after while expression in “do while loop”.
  2. Difference between while loop and do while loop is the place where condition is tested.
  3. ”nested if“ statements cannot be used in while loop, but we can use “nested if” statements in do while loop.
  4. 'do while loop' causes the program to take more time to execute than while loop.
Question 7 Multiple Choice (Single Answer)

What would be the output of the following program?
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int input(int);
int ans(int);
int x,y=0;
x=ans(++(y=(input(x))));
printf(answer=%d,x);
getch();
}
int input(int)
{
int k=7;

      return k;
      }
       int ans(int m)
      {
              return(pow(m,2));
              }
  1. answer = 49
  2. answer = 36
  3. answer = 64
  4. error in the program
  5. none of these
Question 8 Multiple Choice (Single Answer)

What would be the output of the following program?
#include<iostream>
#include<conio.h>
int main()
{

int n=5,i,first=0,second=1,third;
printf(result ”);
printf(“%d %d”,first,second);
for(i=2;i<=5;i++)
{
third=first+second;
printf(“%d”,third);
first=second;
second=third;
}
getch();

}

  1. 0 1 4 9 16 25
  2. 0 1 1 2 3
  3. 0 1 1 2 3 5
  4. Error in program
Question 9 Multiple Choice (Single Answer)

An array has 10 elements. The fifth element is stored at a location in memory address, 2008. If the array is of data type ”long double”, what will be memory address of the first element?

  1. 1968
  2. 1976
  3. 1992
  4. 1972
Question 10 Multiple Choice (Single Answer)

An array is initialised as “static int arr[5]”. If we do not initialize the array in this case, what would be the default initial value of the elements of array?

  1. Zero
  2. Garbage value
  3. Floating number
  4. One(1)
Question 11 Multiple Choice (Single Answer)

What would be the output of the following program?
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int f=1,l,i,x=4,y=6;
float jam;
jam=x;
for(i=2;i<=y;i+=2)
{
f=1;
for(l=1;l<=i;l++)
f=f*l;
jam=jam+pow(x,i)/f;
}
printf(result is %f,jam);
getch();
}

  1. 22.355555
  2. 28.055555
  3. 28.655555
  4. 22.655555
  5. 28.355555
Question 12 Multiple Choice (Single Answer)

What will be the output of the following program?
#include<stdio.h>
#include<conio.h>
#include<math.h>
int rec(int);
int main()
{int input(int);
int result(int);
int x;
x=result(1-input(x)+1);
printf(result=%d,x);
getch();
}
int input(int)
{
int k=5;
return k;
}
int result(int m)
{
return(pow(m,2));
}

  1. answer = 9
  2. answer = 16
  3. answer = 25
  4. garbage value
  5. none of these
Question 13 Multiple Choice (Single Answer)

What would be the output of the following program?
#include<stdio.h>
#include<conio.h>
int main()
{

int i = 2, j = 3, k, l ;
float a, b ;
k = i / j * j ;
l = j / i * i ;
a = i / j * j ;
b = j / i * i ;
printf( %d %d %f %f, k, l, a, b ) ;
getch();
}

  1. k = 0, l = 2, a = 0.00000, b = 2.00000
  2. ERROR:-cannot convert an integer to float
  3. k = 0, l = 2, a = garbage value, b = garbage value
  4. k = 0, l = 2, a = 0, b = 2
  5. None of these
Question 14 Multiple Choice (Single Answer)

Which of the following statements is/are true?
(1)The initialise counter sets for loop to initial value.
(2) The while loop executes the body of loop at least once regardless of the logical condition.
(3) The body of the for loop requires the braces even if we are writing only one statement after the for loop.

  1. Only (1)
  2. Only (2)
  3. Only (3)
  4. Both (1) & (2)
  5. Both (1) & (3)
Question 15 Multiple Choice (Single Answer)

Which of the following rules is/are true for defining a variable in “C language”?
(1) <span style="font-family:" arial;="" font-size:="" small;="">The variable name may be a combination of uppercase letters and a digit, but the digit must start with the variable name.
(2) <span style="font-family:" arial;="" font-size:="" small;="">Variable can be a C keyword.
(3) <span style="font-family:" arial;="" font-size:="" small;="">Spaces are not allowed in a variable defining process.

  1. Only (1)
  2. Only (2)
  3. Only (3)
  4. Both (1) & (3)