Programming (C/C++)

Test your C skill in programming language for campus placements by free online preparation and practice paper tests

30 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

<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);
}

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

<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”);
}

  1. RamanDeep
  2. Raman Deep
  3. Deepn
  4. None of these
Question 3 Multiple Choice (Single Answer)

(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?

  1. I, II, III
  2. II, III
  3. I, II
  4. None of these
Question 4 Multiple Choice (Single Answer)

Which of the following statement correctly obtains the remainder on dividing 5.5 by 1.3?

  1. Rem = 5.5 % 1.3
  2. Rem = modf(5.5,1.3)
  3. Rem = fmod(5.5,1.3)
  4. We cannot determine the reminder while doing floating point division.
Question 5 Multiple Choice (Single Answer)

Which of the following is incorrect?
A recursive function

  1. calls itself
  2. is equivalent to the loop
  3. has termination condition
  4. does not return a value
Question 6 Multiple Choice (Single Answer)

Switch cannot have a ______ type value?

  1. int
  2. char
  3. float
  4. none of these
Question 7 Multiple Choice (Single Answer)

(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?

  1. A, B, C
  2. B, C
  3. C
  4. None of these
Question 8 Multiple Choice (Single Answer)

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));
}

  1. 10 10
  2. 10 1
  3. 1 10
  4. None of these
Question 9 Multiple Choice (Single Answer)

Pick the odd one out.

  1. Malloc()
  2. Calloc()
  3. Realloc()
  4. Free()
Question 10 Multiple Choice (Single Answer)

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);
}

  1. 3 3 3 3
  2. 3 2 3 3
  3. 2 2 2 3
  4. None of these
Question 11 Multiple Choice (Single Answer)

What will be the output of the following question?

main()
{
extern int out;
printf(“%d”,out);
}
int out=100;

  1. 0
  2. Garbage value
  3. 100
  4. None of these
Question 12 Multiple Choice (Single Answer)

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. 1-a, 2-b, 3-c, 4-d
  2. 1-a, 2-d, 3-b, 4-c
  3. 1-a, 2-c, 3-b, 4-d
  4. None of these
Question 13 Multiple Choice (Single Answer)

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. 1 2 3 pp 4 pp 5 pp
  2. 1 2 3 4 5
  3. 1 2 pp pp pp
  4. Error
Question 14 Multiple Choice (Single Answer)

What will be the output of the following function?

main()
{
int a[10];
printf(%d,*a+1-*a+3);
}

  1. Garbage value
  2. 4
  3. Error
  4. None of these
Question 15 Multiple Choice (Single Answer)

What will be the output of the following function?

# include <stdio.h>
void main()
{
char str[10] = “Angel”;
str[6] ='d';
printf(“%s”,str);
}

  1. Angel d
  2. d
  3. Angel
  4. Error
Question 16 Multiple Choice (Single Answer)

(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?

  1. II
  2. I, II
  3. II, III
  4. None of these
Question 17 Multiple Choice (Single Answer)

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. 1
  2. 10
  3. Garbage value
  4. None of these
Question 18 Multiple Choice (Single Answer)

What will be the output of the following function?

main()
{
printf(%x,-1<<4);
}

  1. 1111111111110
  2. -1
  3. fff0
  4. None of these
Question 19 Multiple Choice (Single Answer)

Choose the correct option among the following.

  1. Structure and union are same.
  2. Structure occupies more space then union.
  3. Union occupies more space then structure.
  4. None of these
Question 20 Multiple Choice (Single Answer)

What will be the output of the following function?

main()
{
char *p;
printf(%d %d ,sizeof(*p),sizeof(p));
}

  1. 12
  2. 22
  3. 11
  4. None of these
Question 21 Multiple Choice (Single Answer)

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. 1
  2. 64
  3. 0
  4. None of these
Question 22 Multiple Choice (Single Answer)

What will be the output of the following function?

main()
{
static int var = 5;
printf(%d ,var--);
if(var)
main();
}

  1. Error
  2. 5 5 5(Infinite times)
  3. 5 4 3 2 1
  4. None of these
Question 23 Multiple Choice (Single Answer)

What will be the output of the following function?

#define int char
main()
{
int i=65;
printf(%d,sizeof(i));
}

  1. 1
  2. 2
  3. Error
  4. None of these
Question 24 Multiple Choice (Single Answer)

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);
}

  1. 3 HELLO
  2. 3 hello
  3. Error
  4. None of these
Question 25 Multiple Choice (Single Answer)

(a) Associativity of “COMMA” is L à R.
(b) Associativity of printf function is R à L.
Which of the above is/are TRUE?

  1. (a)
  2. (b)
  3. Both (a) and (b)
  4. None of these
Question 26 Multiple Choice (Single Answer)

Given the piece of code
int a[50];
int *pa;
pa = a;
to access the 6th element, which of the following is incorrect?

  1. *(a+5)
  2. a[5]
  3. pa[5]
  4. *(*pa+5)
Question 27 Multiple Choice (Single Answer)

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);
}

  1. NULL
  2. TRUE
  3. FALSE
  4. No
Question 28 Multiple Choice (Single Answer)

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);
}
}

  1. 0,5,9,13,17
  2. 5,9,13,17
  3. 16,21
  4. Syntax error
Question 29 Multiple Choice (Single Answer)

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);
}

  1. 200
  2. 30
  3. 100
  4. 500
Question 30 Multiple Choice (Single Answer)

<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]);
}

  1. 10
  2. 4
  3. 3
  4. Error