Introduction To Programming

Why programs ? Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time..

Monday, February 15, 2010

23

#include< stdio.h >
#define merge(a,b) a##b
main()
{
int c=merge(4,0);
c=c+1;
printf("%d",c);
return 0;
}

Output:


41


Logic:


in previous post i said about merging operator. Again i'm going to explain what it's.
Merging Operator:
## this will merge given strings and produce concatenation of that strings.
in case of numbers it gives result in the form of numbers.
in this program, i defined a function merge, that'll merge the a and b using merging
operator(a##b). so it'll gives result as 40.

22

#include< stdio.h >
main()
{
char a;
a='A'-17;
printf("%c",a);
return 0;
}


Output


0


Logic:


It's simple logic.
ASCII value of character 'A' is 65.
65-17=48
48 is ASCII value of '0'.

21

#include < stdio.h >
main()
{
float a=1;
switch(a)
{
case 1:
printf("%f",a);
break;
case 1.0:
printf("%f",a);
break;
default:
printf("%f",a);
}
return 0;
}


Output


Compilation Error:
Switch Selection expression must be integral type.
Constant expression required


Logic:



Switch Selection expression must be integral type:
we can give only integer or characters variable to switch case.

Constant expression required:
we can use only integer constants or characters in case.