Pages

Sunday, May 21, 2017

C Programming Aptitude Set-1

Predict the output of following programs with justification.
Question - 1

#include<stdio.h>
int main()
{
  char name[ ]="INDIA";
  int i;
 
  for(i=0; name[i]; i++)
printf("%c%c%c ",name[i],*(name+i),*(i+name));
  return 0;
}

Question - 2

#include<stdio.h>
int main()
{
  int const marks=5;

  printf("%d",marks++);

  return 0;
}

Question - 3

#include<stdio.h>
int main()
{
  static int number = 3;
  printf("%d ",number--);

  if(number)
main();

  return 0;
}

Question - 4

#include<stdio.h>
int main()
{
  float number1 = 5.1;
  double number2 = 5.1;
  if(number1 == number2)
printf("Equal numbers.");
  else
printf("Not equal numbers.");
}

Question - 5

#include<stdio.h>
int main()
{
  char ch='A';
  switch(ch)
  {
default : printf("Error");
case 'A': printf("Hello - A");
 break;
case 'B': printf("Hello B");
 break;
case 'C':   printf("Hello C");
 break;
  }
}

Click here to check your answers.

No comments:

Post a Comment