Programming (C/C++)
Test your C skill in programming language for campus placements by free online preparation and practice paper tests
Questions
<span style="font-size:10.0pt;font-family:Arial;mso-fareast-font-family:"Times" new="" roman";mso-bidi-font-family:arial;color:black;mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa="">What will be the output of the following function?
include <stdio.h>
void main()
{
int a[5] = {5,1,15,20,25};
int i,j,m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf(“%d %d %d”,i,j,m);
}
- 2 1 15
- 1 2 5
- 3 2 15
- 2 2 2
<span style="font-size:10.0pt;font-family:Arial;mso-fareast-font-family:"Times" new="" roman";mso-bidi-font-family:arial;color:black;mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa="">What will be the output of the following function?
main()
{
printf(“RamanDeep”);
}
- RamanDeep
- Raman Deep
- Deepn
- None of these
(I) In C, all the function except main() can be called recursively.
(II) If return type for a function is not specified, its default is int.
(III) A function cannot be defined inside another function.
Which of the above statements are true?
- I, II, III
- II, III
- I, II
- None of these
Which of the following statement correctly obtains the remainder on dividing 5.5 by 1.3?
- Rem = 5.5 % 1.3
- Rem = modf(5.5,1.3)
- Rem = fmod(5.5,1.3)
- We cannot determine the reminder while doing floating point division.
Which of the following is incorrect?
A recursive function
- calls itself
- is equivalent to the loop
- has termination condition
- does not return a value
Switch cannot have a ______ type value?
- int
- char
- float
- none of these
(A) If malloc() successfully allocates memory then returns the number of bytes it has allocated.
(B) malloc() returns a float pointer if memory is allocated for storing float.
(C) malloc() returns a NULL if it fails to allocate request memory.
Which of the above statements are true?
- A, B, C
- B, C
- C
- None of these
What will be the output of the following function?
# define DIM1(array,type) sizeof(array)/sizeof(type)
int DIM2(int array[])
{
return(sizeof(array)/sizeof(int));
}
void main()
{
int arr[10];
printf(“%d %d “, DIM1(arr,int), DIM2(arr));
}
- 10 10
- 10 1
- 1 10
- None of these
Pick the odd one out.
- Malloc()
- Calloc()
- Realloc()
- Free()
What will be the output of the following function?
# include <stdio.h>
void main()
{
int i =2,j=2;
printf(“%d %d %d %d”,i,i++,j,++j);
}
- 3 3 3 3
- 3 2 3 3
- 2 2 2 3
- None of these
What will be the output of the following question?
main()
{
extern int out;
printf(“%d”,out);
}
int out=100;
- 0
- Garbage value
- 100
- None of these
Match the following
| (1) local variables | (a) stack |
| (2) global variable | (b) register |
| (3) register variable | (c) main memory |
| (4) Static variable | (d) data memory |
|
- 1-a, 2-b, 3-c, 4-d
- 1-a, 2-d, 3-b, 4-c
- 1-a, 2-c, 3-b, 4-d
- None of these
What will be the output of the following question?
fun()
{
here:
printf(“pp”);
}
main()
{
int i=1;
while(i<=5)
{
printf(“%d”,i);
if(i>2)
goto here;
i++;
}
}
- 1 2 3 pp 4 pp 5 pp
- 1 2 3 4 5
- 1 2 pp pp pp
- Error
What will be the output of the following function?
main()
{
int a[10];
printf(%d,*a+1-*a+3);
}
- Garbage value
- 4
- Error
- None of these
What will be the output of the following function?
# include <stdio.h>
void main()
{
char str[10] = “Angel”;
str[6] ='d';
printf(“%s”,str);
}
- Angel d
- d
- Angel
- Error
(I) Every time we supply new set of values at command prompt, we need to recompile the program.
(II) Even if integer/float arguments are supplied at command prompt, they are treated as strings.
(III) The first argument to be supplied at command-line must always be the count of total argument.
Which of the above statement/s is/are true about command line argument?
- II
- I, II
- II, III
- None of these
What will be the output of the following function?
main()
{
int i;
printf(%d,scanf(%d,&i));
// value 10 is given as input here
}
- 1
- 10
- Garbage value
- None of these
What will be the output of the following function?
main()
{
printf(%x,-1<<4);
}
- 1111111111110
- -1
- fff0
- None of these
Choose the correct option among the following.
- Structure and union are same.
- Structure occupies more space then union.
- Union occupies more space then structure.
- None of these
What will be the output of the following function?
main()
{
char *p;
printf(%d %d ,sizeof(*p),sizeof(p));
}
- 12
- 22
- 11
- None of these
What will be the output of the following function?
#define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf(%d,i);
}
- 1
- 64
- 0
- None of these
What will be the output of the following function?
main()
{
static int var = 5;
printf(%d ,var--);
if(var)
main();
}
- Error
- 5 5 5(Infinite times)
- 5 4 3 2 1
- None of these
What will be the output of the following function?
#define int char
main()
{
int i=65;
printf(%d,sizeof(i));
}
- 1
- 2
- Error
- None of these
What will be the output of the following function?
#include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]=hello;
};
struct xx *s;
printf(%d,s->x);
printf(%s,s->name);
}
- 3 HELLO
- 3 hello
- Error
- None of these
(a) Associativity of “COMMA” is L à R.
(b) Associativity of printf function is R à L.
Which of the above is/are TRUE?
- (a)
- (b)
- Both (a) and (b)
- None of these
Given the piece of code
int a[50];
int *pa;
pa = a;
to access the 6th element, which of the following is incorrect?
- *(a+5)
- a[5]
- pa[5]
- *(*pa+5)
What will be the output of the following function?
#define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts(NULL);
else if(FALSE)
puts(TRUE);
else
puts(FALSE);
}
- NULL
- TRUE
- FALSE
- No
What will be the output of the following function?
main()
{ int i=0;
for(i=0;i<20;i++)
{ switch(i){
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf(%d,,i);
}
}
- 0,5,9,13,17
- 5,9,13,17
- 16,21
- Syntax error
What will be the output of the following function?
# include <stdio.h>
void main()
{
int k,num=30;
k = (num>5 ? (num <=10 ? 100:200) :500);
printf(“%d”,num);
}
- 200
- 30
- 100
- 500
<span style="font-size:10.0pt;font-family:Arial;mso-fareast-font-family:"Times" new="" roman";mso-bidi-font-family:arial;color:black;mso-ansi-language:en-us;mso-fareast-language:en-us;mso-bidi-language:ar-sa="">What will be the output of the following function?
include<stdio.h>
void fun(int *f)
{
*f = 10;
}
void main()
{
const int arr[5] = {1,2,3,4,5};
fun(&arr[3]);
printf(“%d”,arr[3]);
}
- 10
- 4
- 3
- Error