C Programming for Computer Science and IT
C programming concepts for GATE exam preparation covering arrays, functions, loops, and data types
Questions
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?
- Automatic
- Static
- External
- Both automatic & external
- None of these
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?
- 20 bytes
- 40 bytes
- 10 bytes
- 80 bytes
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.
- Only (1)
- Only (2)
- Only (3)
- Both (1) & (2)
- Both (2) & (3)
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;
}
}
- 140
- 120
- 100
- Error in program
- None of these
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.
- Only (1)
- Only (2)
- Only (3)
- Both (1) & (2)
- Both (2) & (3)
What is the difference between “while loop” and “do while loop”?
- 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”.
- Difference between while loop and do while loop is the place where condition is tested.
- ”nested if“ statements cannot be used in while loop, but we can use “nested if” statements in do while loop.
- 'do while loop' causes the program to take more time to execute than while loop.
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));
}
- answer = 49
- answer = 36
- answer = 64
- error in the program
- none of these
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();
}
- 0 1 4 9 16 25
- 0 1 1 2 3
- 0 1 1 2 3 5
- Error in program
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?
- 1968
- 1976
- 1992
- 1972
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?
- Zero
- Garbage value
- Floating number
- One(1)
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();
}
- 22.355555
- 28.055555
- 28.655555
- 22.655555
- 28.355555
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));
}
- answer = 9
- answer = 16
- answer = 25
- garbage value
- none of these
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();
}
- k = 0, l = 2, a = 0.00000, b = 2.00000
- ERROR:-cannot convert an integer to float
- k = 0, l = 2, a = garbage value, b = garbage value
- k = 0, l = 2, a = 0, b = 2
- None of these
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.
- Only (1)
- Only (2)
- Only (3)
- Both (1) & (2)
- Both (1) & (3)
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.
- Only (1)
- Only (2)
- Only (3)
- Both (1) & (3)