Pages

Saturday, August 25, 2018

Predict C Program Output-3 Answer


Program-1

#include<stdio.h>
int main()
{
  float num=65;
  printf("Size of(num) = %d",printf("65"));
  return 0;
}

Output: 65Size of(num) = 2

Justification: printf("65") written inside will be executed first; hence it prints 65. Also it returns 2 as two characters are printed, which will be printed as a value of %d.


* * * * *
Program-2

#include<stdio.h>
int main()
{
  int number = 97 ;
  printf("%c",number);
  return 0;
}

Output: a

Justification: 'a'  is the corresponding character of ASCII value 97; hence output is a.

* * * * *
Program-3

#include<stdio.h>
int main()
{
  char ch = '0' ;
  printf("%d", ch);
  return 0;
}

Output: 48

Justification: '48'  is the corresponding ASCII value of character '0' (Zero); and format specifier is %d hence output is 48.

* * * * *

Program-4

#include<stdio.h>
int main()
{
  char ch = 0 ;
  printf("%d", ch);
  return 0;
}

Output: 0

Justification: is assigned as a number zero to ch; and format specifier is %d hence output is 0.

* * * * *

Program-5

#include<stdio.h>
#define int char
int main()
{
  int num=65;
  printf("Size of(num) = %d",sizeof(num));
  return 0;
}

Output: Size of(num) = 1

Justification: #define replaces int with char; hence num will be declared as char type variable; hence output is Size of(num) = 1.


No comments:

Post a Comment