Tuesday, June 25, 2013

Important C written Test Programs...


Write a C program to print a message without using semicolon(;)
#include<stdio.h>
#include<stdlib.h>
intmain(void) {
    if(printf("Hello to Ranga")) {
   }
   returnEXIT_SUCCESS;
}
Output: 
Hello to Ranga
Write c program which shutdown the window operating system?
#include<stdio.h>
#include<stdlib.h>
intmain(void) {
system("shutdown -s");
returnEXIT_SUCCESS;
}
Write a c program such that when we will click its .exe file then it will open internet explorer 
#include<stdio.h>
#include<stdlib.h>

intmain(void) {
system("c:\\progra~1\\intern~1\\iexplore.exe");
returnEXIT_SUCCESS;
}
What is the output of the program?
#include<stdio.h>
#include<conio.h>
void main()
{
  clrscr();
printf("%d",printf("%d",printf("10")));
getch();
}

Output: 
1021

What is the output of the following Program?

#include<stdio.h>
void main()
{
char c=0;
for(;c>=0;c++);
printf("%d",c);
}

Output:
-128

What is the output of the following Program?

#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=2;
int c=3,d=4;
clrscr();
if(a,b,c,d)
{
printf("condition is true");
}
else
{
printf("condition is false");
}
getch();
}

Output:
condition is ture

What is the output of the following Program?
 
#include<stdio.h>
#include<conio.h>
void foo();
void main()
{
int i=10;
clrscr();
printf("\n%d",i);
foo();
printf("\n%d",i);
getch();
}
void foo()
{
#undef i
#define i 50
}

Output:

10
10

What is the output of the following Program?

#include<stdio.h>
void main()
{
char c='Z';
printf("\n%c",c);
}

Output:
Z

What is the output of the following Program?

#include<stdio.h>
#include<conio.h>
void main()
{
int i=100;
clrscr();
printf("\n%d",sizeof(sizeof(i)));
getch();
}

Output:
2

What is the output of the following Program?

#include<stdio.h>
#include<conio.h>
void main()
{
int i=5;
clrscr();
printf("%d",main||i);
getch();
}

Output:
1

What is the output of the following Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i=- -5;
clrscr();
printf("%d",i);
getch();
}

Output:
5

Write a program to compare 2 variables without using relational operators.

Concept used:
1: simple if statement, which evaluates true block if the result of the condition becomes non-zero.
2: X-OR Gate & Negation.

#include
void main()
{
int a=12;
int b=14;
if(a/b)
if(!(a^b))
printf("Both are equal");
else
printf("a is big");
else
printf("b is big now!!!!!!!");
}

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char *name ="name";
change(name);
printf("%s",name);
return 0;
}
change(char *name)
{
char *nm="new name";
name=nm;
}
#include <stdio.h>

#define _LINE_ 10
int main(int argc, char *argv[])
{
printf("%d",_LINE_);
return 0;
}

Output:
10

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
if(i++,i) printf("1");
else printf("0");
return 0;
}

Output:
1

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
enum bool{true,false};

if(true==(2==3))
printf("true");
else
printf("false");
return 0;
}

Output:
true

What is the output of the following Program?
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d",(float)3/2);
return 0;
}

Output:
0

What is the output of the following Program? 
#include <stdio.h>
int main(int argc, char *argv[])
{
int a[5]={1,2,3,4,5};
int dif;
int *p=a+1;
int *q=a+5;
dif=q-p;
printf("%d",dif);
return 0;
}

Output:
4

What is the output of the following Program?
 
#include <stdio.h>
#define exp 5
int main(int argc, char *argv[])
{
printf("%d",exp++);
return 0;
}

Output:
error: invalid lvalue in increment

What is the output of the following Program?
#include <stdio.h>
int main(int argc, char *argv[])
{
char *str = "Hello, world" ;
printf("%5s", str);
return 0;
}

Output: 
Hello, world

What is the output of the following Program?
 
#include <stdio.h>
void temp();
void temp(void);
int main(int argc, char *argv[])
{
temp();
return 0;
}

void temp()
{
printf("C is exciting!");
}

Output:
C is exciting!

What is the output of the following Program?
 
#include <stdio.h>
void temp(int);
int main(int argc, char *argv[])
{
temp(1);
return 0;
}

void temp(int i)
{
if(i == 10) return;
i++ ;
temp(i);
printf("%d ", i);
}

Output:
10 9 8 7 6 5 4 3 2

What is the output of the following Program?
#include <stdio.h>
int main(int argc, char *argv[])
{
char *str = "Hello, world";
int i = sizeof(str);
for( ; i >= 0 ; i--)
printf("%c " , str[i]);
return 0;
}

Output:
o l l e H

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *f1;
FILE *f2;
f1=fopen("myfile.txt","w");
f2=fopen("myfile.txt","w");

fputc('A',f1);
fputc('B',f2);

fclose(f1);
fclose(f2);

return 0;
}

Output:
B

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("\n%c",**++argv);
return 0;
}

Output:
f

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int i=3;
while(i--){
int i=100;
i--;
printf("\n%d",i);
}
return 0;
}

Output:
99 99 99

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char s1[]="Hello";
char s2[]="Hello";

if(s1==s2) printf("Same");
else printf("Diff");
return 0;
}

Output:
Diff

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int j=5;
printf("%d",(*&j)++);
return 0;
}

Output:
5

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char c='1';
int j=atoi(c);
printf("%d",j);
return 0;
}


What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int d=5;
printf("%f",d);
return 0;
}

Output:
0.000000

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char *s="\12345s\n";
printf("%s length is %d",s,sizeof(s));
return 0;
}

Output:
S45s
length is 4

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned i=1; /* unsigned char k= -1 => k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i<j)
printf("less");
else
if(i>j)
printf("greater");
else
if(i==j)
printf("equal");
return 0;
}

Output:
less

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
float j;
j=1000*1000;
printf("%f",j);
return 0;
}

Output:

1000000.000000

What is the output of the following Program?
 
#include <stdio.h>
int f();
int main(int argc, char *argv[])
{
f(1);
f(1,2);
f(1,2,3);
return 0;
}
f(int i,int j,int k)
{
printf("\n%d %d %d",i,j,k);
}

Output:

1 2009147472 4199312
1 2 4199312
1 2 3

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int i=7;
printf("%d",i++*i++);
return 0;
}

Output:
49

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=&sum;
*temp=count;
printf("%d %d %d ",count,*temp,sum);

return 0;
}

Output:

20 20 20


What is the output of the following Program?
 
#include <stdio.h>
int main()
{
static i=3;
printf("%d ",i--);
return i>0 ? main():0;
}

Output:
3 2 1

What is the output of the following Program?

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s ",++*p);
printf("%s ",*p++);
printf("%s ",++*p);

return 0;
}

Output:
harma harma ewlett-packard

What a C program thta takes text, convert lower case letters into upper case letters.
 
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i,len;
char name[100];
printf("Enter Name : ");
gets(name);
len=strlen(name);
printf("Name in Lower Case is %s\n",name);

for(i=0;i<len;i++)
{
if(name[i]>='a' && name[i]<='z')
name[i]=(char)name[i]-32;
}

printf("Name in Upper Case is %s",name);
return 0;
}

Output:

Enter Name : ranga reddy
Name in Lower Case is ranga reddy
Name in Upper Case is RANGA REDDY

What is the output of the following Program?

#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1="name";
char *p2;
p2=(char*)malloc(20);
memset(p2, 0, 20);
while(*p2++ = *p1++);
printf("%s",p2);
return 0;
}

Output:
empty string

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int x=20,y=35;
x=y++ + x++;
y=++y + ++x;
printf("%d %d",x,y);
return 0;
}

Output:

57 94

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int x=5;
printf("%d,%d,%d",x,x<<2,x>>2);
return 0;
}

Output:

5,20,1


What is the output of the following Program?

#include <stdio.h>
#define swap(a,b) a=a+b;b=a-b;a=a-b;
int main(int argc, char *argv[])
{
int x=5, y=10;
swap (x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d",x,y);
return 0;
}

int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}

Output:

10 5
10 5


What is the output of the following Program?

#include <stdio.h>
int main(int argc, char *argv[])
{
char *ptr="Ranga Reddy";
*ptr++;
printf("%s\n",ptr);
ptr++;
printf("%s",ptr);
return 0;
}

Output:
anga Reddy
nga Reddy

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char s1[]="Ranga";
char s2[]="Reddy";
printf("%s",s1);
return 0;
}

Output:
Ranga

What is the output of the following Program?

#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1;
char *p2;
p1=(char *)malloc(25);
p2=(char *)malloc(25);
strcpy(p1,"Ranga");
strcpy(p2,"Reddy");
strcat(p1,p2);
printf("%s",p1);

return 0;
}

Output:

RangaReddy

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int x=10, y=15;
x = x++;
y = ++y;
printf("%d %d\n",x,y);
return 0;
}

Output:

10 16

What is the output of the following Program? 

#include <stdio.h>
int main(int argc, char *argv[])
{
int a=0;
if(a==0)
printf("Ranga Reddy\n");
printf("Ranga Reddy");
return 0;
}

Output:
Ranga Reddy
Ranga Reddy

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned int i=10;
while(i>=0)
{
printf("%u",i);
i--;
}

return 0;
}

Output:

Infinite Loop

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
printf("%d",b[-1]);

return 0;
}

Output:

3

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int n=2,sum=1;
switch(n){
case 2:sum=sum+2;
case 3:sum*=2;
break;
default:sum=0;
}
printf("%d",sum);

return 0;
}

Output:
6

What is the output of the following Program?
 
#include <stdio.h>

int main(int argc, char *argv[])
{
int x=5,*p;
p=&x;
printf("%d",++*p);
return 0;
}

Output:  
 6

0 comments: