C Language Practice Programs 1

C Language Practice Programs 1

C Langauge Practice Programs-MCQs-Objective-QuestionsDetermine output:

#include <stdio.h>
void main()
{
char *p = NULL;
char *q = 0;
if(p)
printf(” p “);
else
printf(“nullp”);
if(q)
printf(“q”);
else
printf(” nullq”);
}

  1. p q
  2. Depends on the compiler
  3. x nullq where x can be p or nullp depending on the value of NULL
  4. nullp nullq

Ans: 4


 What is the output?

#include <stdio.h>
void main()
{
printf(“Hi Friends”+3);
}

Output: Friends


 The address operator &, cannot act on

  1. Constants
  2. Arithmetic expressions
  3. Both of the above
  4. Local variables

Ans: 3


What is the output?

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

Ans: 12 or 24


#include<stdio.h>

void main()
{
int *ptr, a=10;
ptr = &a;
*ptr += 1;
printf(“%d, %d”, *ptr, a);
}

  1. 10, 10
  2. 10, 11
  3. 11, 10
  4. 11, 11

Ans: 4


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


What is the output?

#include <stdio.h>
void main()
{
void x(void);
x();
return 0;
}
void x(void)
{
char a[]=”HELLO”;
char *b = “HELLO”;
char c[10]=”HeLLO”;
printf(“%s %s %s\n”,a,b,c);
printf(“%d %d %d\n”,sizeof(a),sizeof(b),sizeof(c));
}

Output: 6  4  10


Determine Output:

void main()
{
char *str1 = “abcd”;
char str2[] = “abcd”;
printf(“%d %d %d”, sizeof(str1), sizeof(str2), sizeof(“abcd”));
}

  1. 2 5 5
  2. 2 4 4
  3. 8 5 5
  4. 2 4 5

Ans: 3


 what is the output?

#include <stdio.h>
void main()
{
register int x =5, *p;
p = &x;
printf(“%d”,*p);
}

Ans: Error


What will be printed after compiling and running the following code?

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

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

Ans: 2


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

Share this post