Sample Questions and answers

1. Rewrite the following program to conform to good programming practice

#include <stdio.h>
int main()
{
    printf("past is past");
}

2. Write a C program that the following phrases at the terminal.

  1. Work is worship
  2. C isa structured language.

3. What is the output of the following programs?

  1. unsigned char x;
    x = 300;
    printf ( "%d", x);
  2. unsigned char x;
    x = 65;
    printf ( "%c", x);
  3. int x-5;
    printf ("%d %d ",x++,x)
    printf ("%d %d ,++x, x);
  4. printf ( "%d %d ",sizeof (char), sizeof (double) );
  5. int x, y;
    x=5;
    y=10;
    printf ( "%d %d %d %d " ,x++, y++, ++x, ++y) ;

Solutions

1.

#include <stdio.h>
int main ()
{
    printf ("past is past 
");
}

2.

#include <stdio.h>
int main ()
{
   printf ("Work is worship
");
   printf ("C is a structured language
");
}

3.

  • 300
  • A
  • 5 5
  • 7 7
  • 1 8
  • 6 11 6 11