C Language Practice Programs 2

C Language Practice Programs 2

C Langauge Practice Programs-MCQs-Objective-Questions

What is the output?

#include <stdio.h>
void main()
{
int a[2][3]={0,1,2,3,4,5};
printf(“%d”,sizeof(a[2]));
}

Ans:  6 or 12


What will be the output of the following program code?

#include <stdio.h>
void main()
{
int i=3, *j, **k;
j = &i;
k = &j;
printf(“%d%d%d”, *j, **k, *(*k));
}

  1. 444
  2. 000
  3. 333
  4. 433

Ans: 3


What is the output?

#include <stdio.h>
void main()
{
int a[]={1,2,3,4,5,6};
int* ptr = a + 2;
printf(“%d”,*–ptr);
}

Ans: 2


Find the output of the following program.

void main()
{
int array[10];
int *i = &array[2], *j = &array[5];
int diff = j-i;
printf(“%d”, diff);
}

  1. 3
  2. 6
  3. Garbage value
  4. Error

Ans: 3


What is the output?

#include <stdio.h>
void main()
{
int a[5]={1,3,6,7,0};
int* b;
b = &a[2];
printf(“%d”,b[-1]);
}

Ans: 3


Attend Free Demo and Learn   C LANGUAGE ONLINE TRAINING   by Real-Time Expert


Find the output of the following program.

void main()
{
printf(“%d, %d”, sizeof(int *), sizeof(int **));
}

  1. 2, 0
  2. 0, 2
  3. 2, 2
  4. 2, 4

Ans: 3


Which of the following statements are true after execution of the program.

void main()
{
int a[10], i, *p;
a[0] = 1;
a[1] = 2;
p = a;
(*p)++;
}

  1. a[1] = 3
  2. a[0] = 2
  3. a[1] = 2
  4. a[0] = 3

Ans: 2


What is the output?

#include <stdio.h>
void main()
{
char* str = “This is my string”;
str[3] = ‘B’;
puts(str);
}

Ans: ThiB is my string


What would be the output for the following Turbo C code?

void main()
{
int a[]={ 1, 2, 3, 4, 5 }, *p;
p=a;
++*p;
printf(“%d “, *p);
p += 2;
printf(“%d”, *p);
}

  1. 2 4
  2. 3 4
  3. 2 2
  4. 2 3

Ans: 4


What is the output?

void main()
{
int *p;  float *q;  double *r
printf(“\n %d\n”, sizeof(p));
printf(“\n %d\n”, sizeof(q));
printf(“\n %d\n”, sizeof(r));
printf(“\n %d\n”, sizeof(char *));
}

Ans: 2 2 2 2


 What is the output?

void main()
{
int a;
int *p;
a = 14;
p = &a;
printf(“%d %p \n”, a, &a);
printf(“%p %d %d\n”, p, *p, a);
}

Ans: 14  Address of a

Address of a    14   14


 What is the output?

void main()
{
char a = ‘x’, *p1 = &a;
int b = 12, *p2 = &b;
float c = 12.4, *p3 = &c;
double d = 18.3, *p4 =&d;
printf(“%d %d\n”, sizeof(p1), sizeof(*p1));
printf(“%d %d\n”, sizeof(p2), sizeof(*p2));
printf(“%d %d\n”, sizeof(p3), sizeof(*p3));
printf(“%d %d\n”, sizeof(p4), sizeof(*p4));
}

Ans:

2    1
2    2
2    4
2    8


Attend Free Demo and Learn   C LANGUAGE ONLINE TRAINING   by Real-Time Expert

Share this post


Azure-devops- online training
Python online traning
MS-Azure-online training
Angular9 online training
AWS online training

Specialization on Trending Courses

Linix online training
Advance Spring online training
fullstack online training
Core java onlne training
Android online training
C#-net online training
SQL online training