Can you help me with
this one?
Make a program that
when a user inputed a
Product Name, it will
display its price, and
when the user inputed
the quantity of the
inputed product, it will
show its total price.
The output must be like
this:
Product Name:
Price:
Quantity:
Total Price:
..this is the list of
products to be inputed:
Cellphone - 1500
Washing Machine - 5200
Television - 6000
Refrigirator - 8000
Oven - 2000
Computer - 11000
thanks..:D
1.Between 100 and 999 are some numbers that have the
characteristics that if you cube the individual digits and
sum together you will get the same number.
2. A program that can accept as input an integer and output
the equivalent of that number in words.
C Questions
Note : All the programs are tested under Turbo C/C++
compilers.
It is assumed that,
 Programs run under DOS environment,
 The underlying machine is an x86 system,
 Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on
this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:
1. void main()
{
int const * p=5;
printf("%d",++(*p));
}
2. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
3. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
4. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
5. main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}
6. main()
{
extern int i;
i=20;
printf("%d",i);
}
7. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}
8. main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}
9. main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
10. main()
{
printf("%x",-1<<4);
}
11. main()
{
char string[]="Hello World";
display(string);
}
void display(char *string)
{
printf("%s",string);
}
12. main()
{
int c=- -2;
printf("c=%d",c);
}
13. #define int char
main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
14. main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}
15. #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
16. #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}
17. #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
18. #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
19. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
20. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
21. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
22. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}
23. #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
24. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
25. main()
{
printf("%p",main);
}
27) main()
{
clrscr();
}
clrscr();
28) enum colors {BLACK,BLUE,GREEN}
main()
{
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
}
29) void main()
{
char far *farther,*farthest;
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
30) main()
{
int i=400,j=300;
printf("%d..%d");
}
31) main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
32) main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
33) main()
{
static char
names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}
34) void main()
{
int i=5;
printf("%d",i++ + ++i);
}
35) void main()
{
int i=5;
printf("%d",i+++++i);
}
36) #include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
37) main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
38) #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
39) main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
40) #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
41) #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}
42) #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
43) main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
44) main()
{
printf("%d", out);
}
int out=100;
45) main()
{
extern out;
printf("%d", out);
}
int out=100;
46) main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
47) main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(%u %u %u %d \n,a,*a,**a,***a);
printf(%u %u %u %d \n,a+1,*a+1,**a+1,***a+1);
}
48) main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{
printf(%d ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf(%d ,*p);
p++;
}
}
49) main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
}
50) main( )
{
char *q;
int j;
for (j=0; j<3; j++) scanf(%s ,(q+j));
for (j=0; j<3; j++) printf(%c ,*(q+j));
for (j=0; j<3; j++) printf(%s ,(q+j));
}
51) main( )
{
void *vp;
char ch = g, *cp = goofy;
int j = 20;
vp = &ch;
printf(%c, *(char *)vp);
vp = &j;
printf(%d,*(int *)vp);
vp = cp;
printf(%s,(char *)vp + 3);
}
52) main ( )
{
static char *s[ ] = {black, white, yellow, violet};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(%s,*--*++p + 3);
}
53) main()
{
int i, n;
char *x = girl;
n = strlen(x);
*x = x[n];
for(i=0; i<n; ++i)
{
printf(%s\n,x);
x++;
}
}
54) int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
55) main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}
56) What are the files which are automatically opened when a
C file is executed?
57) what will be the position of the file marker?
a: fseek(ptr,0,SEEK_SET);
b: fseek(ptr,0,SEEK_CUR);
58) main()
{
char name[10],s[12];
scanf(" \"%[^\"]\"",s);
}
How scanf will execute?
59) What is the problem with the following code segment?
while ((fgets(receiving array,50,file_ptr)) != EOF)
;
60) main()
{
main();
}
61) main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}
62) main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
63) main()
{
char not;
not=!2;
printf("%d",not);
}
64) #define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}
65) main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}
66) main()
{
int y;
scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}
67) #define max 5
#define int arr1[max]
main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
arr2 name="name";
printf("%d %s",list[0],name);
}
68) int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
69) main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
70) main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}
71) #include<stdio.h>
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
72) #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}
73) #include<stdio.h>
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}
74) main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}
76) struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}
77) struct point
{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
78) main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
79) main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}
80) main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}
81) main(int argc, char **argv)
{
printf("enter the character");
getchar();
sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
return num1+num2;
}
82) # include <stdio.h>
int one_d[]={1,2,3};
main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}
83) # include<stdio.h>
aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("bye");
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}
85) #include<stdio.h>
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}
86) main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}
87) main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}
88) int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
89) main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
90) main(){
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}
91) In the following pgm add a stmt in the function fun
such that the address of
'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
}
92) What are the following notations of defining functions
known as?
i. int abc(int a,float b)
{
/* some code */
}
ii. int abc(a,b)
int a; float b;
{
/* some code*/
}
93) main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}
94) main(){
char a[100];
a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
abc(a);
}
abc(char a[]){
a++;
printf("%c",*a);
a++;
printf("%c",*a);
}
95) func(a,b)
int a,b;
{
return( a= (a==b) );
}
main()
{
int process(),func();
printf("The value of process is %d !\n ",process(func,3,6));
}
process(pf,val1,val2)
int (*pf) ();
int val1,val2;
{
return((*pf) (val1,val2));
}
96) void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
97) void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}
98) void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("here in 3 %d\n",++i);
}
99) void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}
100) void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
C,C++ Questions
1. Base class has some virtual method and derived class has
a method with the same name. If we initialize the base class
pointer with derived
object,. calling of that virtual method will result in which
method being called?
a. Base method
b. Derived method..
2. For the following C program
#define AREA(x)(3.14*x*x)
main()
{float r1=6.25,r2=2.5,a;
a=AREA(r1);
printf("\n Area of the circle is %f", a);
a=AREA(r2);
printf("\n Area of the circle is %f", a);
}
What is the output?
3. What do the following statements indicate. Explain.
int(*p)[10]
int*f()
int(*pf)()
int*p[10]
4.
void main()
{
int d=5;
printf("%f",d);
}
5.
void main()
{
int i;
for(i=1;i<4,i++)
switch(i)
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
switch(i) case 4:printf("%d",i);
}
6.
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}
7.
void main()
{
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");
}
8.
void main()
{
float j;
j=1000*1000;
printf("%f",j);
}
1. 1000000
2. Overflow
3. Error
4. None
9. How do you declare an array of N pointers to functions
returning
pointers to functions returning pointers to characters?
10. A structure pointer is defined of the type time . With 3
fields min,sec hours having pointers to intergers.
Write the way to initialize the 2nd element to 10.
11. In the above question an array of pointers is declared.
Write the statement to initialize the 3rd element of the
2 element to 10;
12.
int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}
What are the number of syntax errors in the above?
13.
void main()
{
int i=7;
printf("%d",i++*i++);
}
14.
#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
15.
void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
16. There was question in c working only on unix machine
with pattern matching.
14. what is alloca()
17.
main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}
18.
char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}
19.
void main()
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s",++*p);
printf("%s",*p++);
printf("%s",++*p);
}
20. Output of the following program is
main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
e) Syntax error
21. What is the ouptut in the following program
main()
{char c=-64;
int i=-32
unsigned int u =-16;
if(c>i)
{printf("pass1,");
if(c<u)
printf("pass2");
else
printf("Fail2");
}
else
printf("Fail1);
if(i<u)
printf("pass2");
else
printf("Fail2")
}
a) Pass1,Pass2
b) Pass1,Fail2
c) Fail1,Pass2
d) Fail1,Fail2
e) None of these
22. What will the following program do?
void main()
{
int i;
char a[]="String";
char *p="New Sring";
char *Temp;
Temp=a;
a=malloc(strlen(p) + 1);
strcpy(a,p); //Line number:9//
p = malloc(strlen(Temp) + 1);
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
} //Line number 15//
a) Swap contents of p & a and print:(New string, string)
b) Generate compilation error in line number 8
c) Generate compilation error in line number 5
d) Generate compilation error in line number 7
e) Generate compilation error in line number 1
23. In the following code segment what will be the result of
the function,
value of x , value of y
{unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
a) same, MAXINT, -1
b) not same, MAXINT, -MAXINT
c) same , MAXUNIT, -1
d) same, MAXUNIT, MAXUNIT
e) not same, MAXINT, MAXUNIT
24. What will be the result of the following program ?
char *gxxx()
{static char xxx[1024];
return xxx;
}
main()
{char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is : %s",gxxx());
}
a) The string is : string
b) The string is :Oldstring
c) Run time error/Core dump
d) Syntax error during compilation
e) None of these
25. Find the output for the following C program
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
26. Find the output for the following C program
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
27. Find the output for the following C program
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
28 Find the output for the following C program
#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return;
}
29 Find the output for the following C program
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
30 Find the output for the following C program
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
31 Find the output for the following C program
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
32. Find the output for the following C program given that
[1]. The following variable is available in file1.c
static int average_float;
33. Find the output for the following C program
# define TRUE 0
some code
while(TRUE)
{
some code
}
34. struct list{
int x;
struct list *next;
}*head;
the struct head.x =100
Is the above assignment to pointer is correct or wrong ?
35.What is the output of the following ?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
36. FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)
}
Find the Error, If Any?
37. What are the output(s) for the following ?
38. #include<malloc.h>
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye");
}
main()
{
char *f();
printf("%c",*f()='A'); }
39. #define MAN(x,y) (x)>(y)?(x):(y)
{int i=10;
j=5;
k=0;
k=MAX(i++,++j);
printf(%d %d %d %d,i,j,k);
}
40.
void main()
{
int i=7;
printf("%d",i++*i++);
}
C,C++ Questions
1. Base class has some virtual method and derived class has
a method with the same name. If we initialize the base class
pointer with derived
object,. calling of that virtual method will result in which
method being called?
a. Base method
b. Derived method..
2. For the following C program
#define AREA(x)(3.14*x*x)
main()
{float r1=6.25,r2=2.5,a;
a=AREA(r1);
printf("\n Area of the circle is %f", a);
a=AREA(r2);
printf("\n Area of the circle is %f", a);
}
What is the output?
3. What do the following statements indicate. Explain.
int(*p)[10]
int*f()
int(*pf)()
int*p[10]
4.
void main()
{
int d=5;
printf("%f",d);
}
5.
void main()
{
int i;
for(i=1;i<4,i++)
switch(i)
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
switch(i) case 4:printf("%d",i);
}
6.
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}
7.
void main()
{
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");
}
8.
void main()
{
float j;
j=1000*1000;
printf("%f",j);
}
1. 1000000
2. Overflow
3. Error
4. None
9. How do you declare an array of N pointers to functions
returning
pointers to functions returning pointers to characters?
10. A structure pointer is defined of the type time . With 3
fields min,sec hours having pointers to intergers.
Write the way to initialize the 2nd element to 10.
11. In the above question an array of pointers is declared.
Write the statement to initialize the 3rd element of the
2 element to 10;
12.
int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}
What are the number of syntax errors in the above?
13.
void main()
{
int i=7;
printf("%d",i++*i++);
}
14.
#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
15.
void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
16. There was question in c working only on unix machine
with pattern matching.
14. what is alloca()
17.
main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}
18.
char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}
19.
void main()
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s",++*p);
printf("%s",*p++);
printf("%s",++*p);
}
20. Output of the following program is
main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
e) Syntax error
21. What is the ouptut in the following program
main()
{char c=-64;
int i=-32
unsigned int u =-16;
if(c>i)
{printf("pass1,");
if(c<u)
printf("pass2");
else
printf("Fail2");
}
else
printf("Fail1);
if(i<u)
printf("pass2");
else
printf("Fail2")
}
a) Pass1,Pass2
b) Pass1,Fail2
c) Fail1,Pass2
d) Fail1,Fail2
e) None of these
22. What will the following program do?
void main()
{
int i;
char a[]="String";
char *p="New Sring";
char *Temp;
Temp=a;
a=malloc(strlen(p) + 1);
strcpy(a,p); //Line number:9//
p = malloc(strlen(Temp) + 1);
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
} //Line number 15//
a) Swap contents of p & a and print:(New string, string)
b) Generate compilation error in line number 8
c) Generate compilation error in line number 5
d) Generate compilation error in line number 7
e) Generate compilation error in line number 1
23. In the following code segment what will be the result of
the function,
value of x , value of y
{unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
a) same, MAXINT, -1
b) not same, MAXINT, -MAXINT
c) same , MAXUNIT, -1
d) same, MAXUNIT, MAXUNIT
e) not same, MAXINT, MAXUNIT
24. What will be the result of the following program ?
char *gxxx()
{static char xxx[1024];
return xxx;
}
main()
{char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is : %s",gxxx());
}
a) The string is : string
b) The string is :Oldstring
c) Run time error/Core dump
d) Syntax error during compilation
e) None of these
25. Find the output for the following C program
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
26. Find the output for the following C program
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
27. Find the output for the following C program
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
28 Find the output for the following C program
#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return;
}
29 Find the output for the following C program
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
30 Find the output for the following C program
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
31 Find the output for the following C program
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
32. Find the output for the following C program given that
[1]. The following variable is available in file1.c
static int average_float;
33. Find the output for the following C program
# define TRUE 0
some code
while(TRUE)
{
some code
}
34. struct list{
int x;
struct list *next;
}*head;
the struct head.x =100
Is the above assignment to pointer is correct or wrong ?
35.What is the output of the following ?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
36. FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)
}
Find the Error, If Any?
37. What are the output(s) for the following ?
38. #include<malloc.h>
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye");
}
main()
{
char *f();
printf("%c",*f()='A'); }
39. #define MAN(x,y) (x)>(y)?(x):(y)
{int i=10;
j=5;
k=0;
k=MAX(i++,++j);
printf(%d %d %d %d,i,j,k);
}
40.
void main()
{
int i=7;
printf("%d",i++*i++);
}
C Questions
Note : All the programs are tested under Turbo C/C++
compilers.
It is assumed that,
 Programs run under DOS environment,
 The underlying machine is an x86 system,
 Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on
this assumptions (for example sizeof(int) == 2 may be assumed).
Predict the output or error(s) for the following:
1. void main()
{
int const * p=5;
printf("%d",++(*p));
}
2. main()
{
char s[ ]="man";
int i;
for(i=0;s[ i ];i++)
printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
3. main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}
4. main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
5. main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}
6. main()
{
extern int i;
i=20;
printf("%d",i);
}
7. main()
{
int i=-1,j=-1,k=0,l=2,m;
m=i++&&j++&&k++||l++;
printf("%d %d %d %d %d",i,j,k,l,m);
}
8. main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
}
9. main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
}
10. main()
{
printf("%x",-1<<4);
}
11. main()
{
char string[]="Hello World";
display(string);
}
void display(char *string)
{
printf("%s",string);
}
12. main()
{
int c=- -2;
printf("c=%d",c);
}
13. #define int char
main()
{
int i=65;
printf("sizeof(i)=%d",sizeof(i));
}
14. main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}
15. #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
16. #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}
17. #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
18. #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
19. main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
20. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
21. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
22. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
}
23. #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
24. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
25. main()
{
printf("%p",main);
}
27) main()
{
clrscr();
}
clrscr();
28) enum colors {BLACK,BLUE,GREEN}
main()
{
printf("%d..%d..%d",BLACK,BLUE,GREEN);
return(1);
}
29) void main()
{
char far *farther,*farthest;
printf("%d..%d",sizeof(farther),sizeof(farthest));
}
30) main()
{
int i=400,j=300;
printf("%d..%d");
}
31) main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
}
32) main()
{
int i=1;
while (i<=5)
{
printf("%d",i);
if (i>2)
goto here;
i++;
}
}
fun()
{
here:
printf("PP");
}
33) main()
{
static char
names[5][20]={"pascal","ada","cobol","fortran","perl"};
int i;
char *t;
t=names[3];
names[3]=names[4];
names[4]=t;
for (i=0;i<=4;i++)
printf("%s",names[i]);
}
34) void main()
{
int i=5;
printf("%d",i++ + ++i);
}
35) void main()
{
int i=5;
printf("%d",i+++++i);
}
36) #include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
{
case 1: printf("GOOD");
break;
case j: printf("BAD");
break;
}
}
37) main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as input here
}
38) #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
39) main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
}
40) #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
41) #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
}
42) #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
struct xx *p;
};
struct yy *q;
};
}
43) main()
{
extern int i;
i=20;
printf("%d",sizeof(i));
}
44) main()
{
printf("%d", out);
}
int out=100;
45) main()
{
extern out;
printf("%d", out);
}
int out=100;
46) main()
{
show();
}
void show()
{
printf("I'm the greatest");
}
47) main( )
{
int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
printf(%u %u %u %d \n,a,*a,**a,***a);
printf(%u %u %u %d \n,a+1,*a+1,**a+1,***a+1);
}
48) main( )
{
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)
{
printf(%d ,*a);
a++;
}
p = a;
for(j=0; j<5; j++)
{
printf(%d ,*p);
p++;
}
}
49) main( )
{
static int a[ ] = {0,1,2,3,4};
int *p[ ] = {a,a+1,a+2,a+3,a+4};
int **ptr = p;
ptr++;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
*ptr++;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
*++ptr;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
++*ptr;
printf(\n %d %d %d, ptr-p, *ptr-a, **ptr);
}
50) main( )
{
char *q;
int j;
for (j=0; j<3; j++) scanf(%s ,(q+j));
for (j=0; j<3; j++) printf(%c ,*(q+j));
for (j=0; j<3; j++) printf(%s ,(q+j));
}
51) main( )
{
void *vp;
char ch = g, *cp = goofy;
int j = 20;
vp = &ch;
printf(%c, *(char *)vp);
vp = &j;
printf(%d,*(int *)vp);
vp = cp;
printf(%s,(char *)vp + 3);
}
52) main ( )
{
static char *s[ ] = {black, white, yellow, violet};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
p = ptr;
**++p;
printf(%s,*--*++p + 3);
}
53) main()
{
int i, n;
char *x = girl;
n = strlen(x);
*x = x[n];
for(i=0; i<n; ++i)
{
printf(%s\n,x);
x++;
}
}
54) int i,j;
for(i=0;i<=10;i++)
{
j+=5;
assert(i<5);
}
55) main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
}
56) What are the files which are automatically opened when a
C file is executed?
57) what will be the position of the file marker?
a: fseek(ptr,0,SEEK_SET);
b: fseek(ptr,0,SEEK_CUR);
58) main()
{
char name[10],s[12];
scanf(" \"%[^\"]\"",s);
}
How scanf will execute?
59) What is the problem with the following code segment?
while ((fgets(receiving array,50,file_ptr)) != EOF)
;
60) main()
{
main();
}
61) main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
}
62) main()
{
char *str1="abcd";
char str2[]="abcd";
printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
}
63) main()
{
char not;
not=!2;
printf("%d",not);
}
64) #define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
}
65) main()
{
int k=1;
printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
}
66) main()
{
int y;
scanf("%d",&y); // input given is 2000
if( (y%4==0 && y%100 != 0) || y%100 == 0 )
printf("%d is a leap year");
else
printf("%d is not a leap year");
}
67) #define max 5
#define int arr1[max]
main()
{
typedef char arr2[max];
arr1 list={0,1,2,3,4};
arr2 name="name";
printf("%d %s",list[0],name);
}
68) int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
}
69) main()
{
int *j;
{
int i=10;
j=&i;
}
printf("%d",*j);
}
70) main()
{
int i=-1;
-i;
printf("i = %d, -i = %d \n",i,-i);
}
71) #include<stdio.h>
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
}
72) #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d..%d",*p,*q);
}
73) #include<stdio.h>
main()
{
register i=5;
char j[]= "hello";
printf("%s %d",j,i);
}
74) main()
{
int i=5,j=6,z;
printf("%d",i+++j);
}
76) struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
}
77) struct point
{
int x;
int y;
};
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
78) main()
{
int i=_l_abc(10);
printf("%d\n",--i);
}
int _l_abc(int i)
{
return(i++);
}
79) main()
{
char *p;
int *q;
long *r;
p=q=r=0;
p++;
q++;
r++;
printf("%p...%p...%p",p,q,r);
}
80) main()
{
char c=' ',x,convert(z);
getc(c);
if((c>='a') && (c<='z'))
x=convert(c);
printf("%c",x);
}
convert(z)
{
return z-32;
}
81) main(int argc, char **argv)
{
printf("enter the character");
getchar();
sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
return num1+num2;
}
82) # include <stdio.h>
int one_d[]={1,2,3};
main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}
83) # include<stdio.h>
aaa() {
printf("hi");
}
bbb(){
printf("hello");
}
ccc(){
printf("bye");
}
main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[2]();
}
85) #include<stdio.h>
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}
86) main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}
87) main()
{
int i;
i = abc();
printf("%d",i);
}
abc()
{
_AX = 1000;
}
88) int i;
main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--",t--);
}
// If the inputs are 0,1,2,3 find the o/p
89) main(){
int a= 0;int b = 20;char x =1;char y =10;
if(a,b,x,y)
printf("hello");
}
90) main(){
unsigned int i;
for(i=1;i>-2;i--)
printf("c aptitude");
}
91) In the following pgm add a stmt in the function fun
such that the address of
'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
}
92) What are the following notations of defining functions
known as?
i. int abc(int a,float b)
{
/* some code */
}
ii. int abc(a,b)
int a; float b;
{
/* some code*/
}
93) main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
}
94) main(){
char a[100];
a[0]='a';a[1]]='b';a[2]='c';a[4]='d';
abc(a);
}
abc(char a[]){
a++;
printf("%c",*a);
a++;
printf("%c",*a);
}
95) func(a,b)
int a,b;
{
return( a= (a==b) );
}
main()
{
int process(),func();
printf("The value of process is %d !\n ",process(func,3,6));
}
process(pf,val1,val2)
int (*pf) ();
int val1,val2;
{
return((*pf) (val1,val2));
}
96) void main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
97) void main()
{
int k=ret(sizeof(float));
printf("\n here value is %d",++k);
}
int ret(int ret)
{
ret += 2.5;
return(ret);
}
98) void main()
{
char a[]="12345\0";
int i=strlen(a);
printf("here in 3 %d\n",++i);
}
99) void main()
{
unsigned giveit=-1;
int gotit;
printf("%u ",++giveit);
printf("%u \n",gotit=--giveit);
}
100) void main()
{
int i;
char a[]="\0";
if(printf("%s\n",a))
printf("Ok here \n");
else
printf("Forget it\n");
}
C,C++ Questions
1. Base class has some virtual method and derived class has
a method with the same name. If we initialize the base class
pointer with derived
object,. calling of that virtual method will result in which
method being called?
a. Base method
b. Derived method..
2. For the following C program
#define AREA(x)(3.14*x*x)
main()
{float r1=6.25,r2=2.5,a;
a=AREA(r1);
printf("\n Area of the circle is %f", a);
a=AREA(r2);
printf("\n Area of the circle is %f", a);
}
What is the output?
3. What do the following statements indicate. Explain.
int(*p)[10]
int*f()
int(*pf)()
int*p[10]
4.
void main()
{
int d=5;
printf("%f",d);
}
5.
void main()
{
int i;
for(i=1;i<4,i++)
switch(i)
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
switch(i) case 4:printf("%d",i);
}
6.
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}
7.
void main()
{
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");
}
8.
void main()
{
float j;
j=1000*1000;
printf("%f",j);
}
1. 1000000
2. Overflow
3. Error
4. None
9. How do you declare an array of N pointers to functions
returning
pointers to functions returning pointers to characters?
10. A structure pointer is defined of the type time . With 3
fields min,sec hours having pointers to intergers.
Write the way to initialize the 2nd element to 10.
11. In the above question an array of pointers is declared.
Write the statement to initialize the 3rd element of the
2 element to 10;
12.
int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}
What are the number of syntax errors in the above?
13.
void main()
{
int i=7;
printf("%d",i++*i++);
}
14.
#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
15.
void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=∑
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}
16. There was question in c working only on unix machine
with pattern matching.
14. what is alloca()
17.
main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}
18.
char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}
19.
void main()
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s",++*p);
printf("%s",*p++);
printf("%s",++*p);
}
20. Output of the following program is
main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}
a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
e) Syntax error
21. What is the ouptut in the following program
main()
{char c=-64;
int i=-32
unsigned int u =-16;
if(c>i)
{printf("pass1,");
if(c<u)
printf("pass2");
else
printf("Fail2");
}
else
printf("Fail1);
if(i<u)
printf("pass2");
else
printf("Fail2")
}
a) Pass1,Pass2
b) Pass1,Fail2
c) Fail1,Pass2
d) Fail1,Fail2
e) None of these
22. What will the following program do?
void main()
{
int i;
char a[]="String";
char *p="New Sring";
char *Temp;
Temp=a;
a=malloc(strlen(p) + 1);
strcpy(a,p); //Line number:9//
p = malloc(strlen(Temp) + 1);
strcpy(p,Temp);
printf("(%s, %s)",a,p);
free(p);
free(a);
} //Line number 15//
a) Swap contents of p & a and print:(New string, string)
b) Generate compilation error in line number 8
c) Generate compilation error in line number 5
d) Generate compilation error in line number 7
e) Generate compilation error in line number 1
23. In the following code segment what will be the result of
the function,
value of x , value of y
{unsigned int x=-1;
int y;
y = ~0;
if(x == y)
printf("same");
else
printf("not same");
}
a) same, MAXINT, -1
b) not same, MAXINT, -MAXINT
c) same , MAXUNIT, -1
d) same, MAXUNIT, MAXUNIT
e) not same, MAXINT, MAXUNIT
24. What will be the result of the following program ?
char *gxxx()
{static char xxx[1024];
return xxx;
}
main()
{char *g="string";
strcpy(gxxx(),g);
g = gxxx();
strcpy(g,"oldstring");
printf("The string is : %s",gxxx());
}
a) The string is : string
b) The string is :Oldstring
c) Run time error/Core dump
d) Syntax error during compilation
e) None of these
25. Find the output for the following C program
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
26. Find the output for the following C program
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}
27. Find the output for the following C program
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
28 Find the output for the following C program
#define swap1(a,b) a=a+b;b=a-b;a=a-b;
main()
{
int x=5,y=10;
swap1(x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d\n",x,y);
}
int swap2(int a,int b)
{
int temp;
temp=a;
b=a;
a=temp;
return;
}
29 Find the output for the following C program
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
30 Find the output for the following C program
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
31 Find the output for the following C program
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
32. Find the output for the following C program given that
[1]. The following variable is available in file1.c
static int average_float;
33. Find the output for the following C program
# define TRUE 0
some code
while(TRUE)
{
some code
}
34. struct list{
int x;
struct list *next;
}*head;
the struct head.x =100
Is the above assignment to pointer is correct or wrong ?
35.What is the output of the following ?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
36. FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)
}
Find the Error, If Any?
37. What are the output(s) for the following ?
38. #include<malloc.h>
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye");
}
main()
{
char *f();
printf("%c",*f()='A'); }
39. #define MAN(x,y) (x)>(y)?(x):(y)
{int i=10;
j=5;
k=0;
k=MAX(i++,++j);
printf(%d %d %d %d,i,j,k);
}
40.
void main()
{
int i=7;
printf("%d",i++*i++);
}
C QUESTIONS
How do you decide which integer type to use?
What should the 64-bit type on a machine that can support it?
What's the best way to declare and define global variables
and functions?
What does extern mean in a function declaration?
What's the auto keyword good for?
I can't seem to define a linked list successfully. I tried
typedef struct {
char *item;
NODEPTR next;
} *NODEPTR;
but the compiler gave me error messages. Can't a structure
in C
contain a pointer to itself?
How do I declare an array of N pointers to functions returning
pointers to functions returning pointers to characters?
How can I declare a function that can return a pointer to a
function of the same type?
What's the right declaration for main()?
Is void main() correct?
What am I allowed to assume about the initial values
of variables which are not explicitly initialized?
If global variables start out as "zero", is that good
enough for null pointers and floating-point zeroes?
This code, straight out of a book, isn't compiling:
int f()
{
char a[] = "Hello, world!";
}
What's wrong with this initialization?
char *p = malloc(10);
What is the difference between these initializations?
char a[] = "string literal";
char *p = "string literal";
What's the difference between these two declarations?
struct x1 { ... };
typedef struct { ... } x2;
Why doesn't
struct x { ... };
x thestruct;
work?
Can a structure contain a pointer to itself?
What's the best way of implementing opaque (abstract) data types
in C?
I came across some code that declared a structure like this:
struct name {
int namelen;
char namestr[1];
};
and then did some tricky allocation to make the namestr array
act like it had several elements. Is this legal or portable?
Is there a way to compare structures automatically?
How can I pass constant values to functions which accept
structure arguments?
How can I read/write structures from/to data files?
Why does sizeof report a larger size than I expect for a
structure type, as if there were padding at the end?
How can I determine the byte offset of a field within a
structure?
How can I access structure fields by name at run time?
This program works correctly, but it dumps core after it
finishes. Why?
struct list {
char *item;
struct list *next;
}
/* Here is the main program. */
main(argc, argv)
{ ... }
Can I initialize unions?
What is the difference between an enumeration and a set of
preprocessor #defines?
Is there an easy way to print enumeration values symbolically?
Why doesn't this code:
a[i] = i++;
work?
I've experimented with the code
int i = 3;
i = i++;
on several compilers. Some gave i the value 3, and some gave 4.
Which compiler is correct?
Can I use explicit parentheses to force the order of evaluation
I want? Even if I don't, doesn't precedence dictate it?
How can I understand these complex expressions? What's a
"sequence point"?
If I'm not using the value of the expression, should I use i++
or ++i to increment a variable?
Why doesn't the code
int a = 1000, b = 1000;
long int c = a * b;
work?
I'm trying to declare a pointer and allocate some space for it,
but it's not working. What's wrong with this code?
char *p;
*p = malloc(10);
Does *p++ increment p, or what it points to?
I have a char * pointer that happens to point to some ints, and
I want to step it over them. Why doesn't
((int *)p)++;
work?
I have a function which accepts, and is supposed to initialize,
a pointer:
void f(int *ip)
{
static int dummy = 5;
ip = &dummy;
}
But when I call it like this:
int *ip;
f(ip);
the pointer in the caller remains unchanged.
Why?
Can I use a void ** pointer as a parameter so that a function
can accept a generic pointer by reference?
I have a function
extern int f(int *);
which accepts a pointer to an int. How can I pass a
constant by
reference? A call like
f(&5);
doesn't seem to work.
Does C even have "pass by reference"?
What is infamous null pointer?
How do I get a null pointer in my programs?
Is the abbreviated pointer comparison "if(p)" to test for non-
null pointers valid? What if the internal representation for
null pointers is nonzero?
What is NULL and how is it #defined?
How should NULL be defined on a machine which uses a nonzero bit
pattern as the internal representation of a null pointer?
If NULL were defined as follows:
#define NULL ((char *)0)
wouldn't that make function calls which pass an uncast NULL
work?
If NULL and 0 are equivalent as null pointer constants,
which should I use?
What does a run-time "null pointer assignment" error mean?
How can I track it down?
Why are array and pointer declarations interchangeable as
function formal parameters?
How can an array be an lvalue, if you can't assign to it?
Practically speaking, what is the difference between arrays
and pointers?
How do I declare a pointer to an array?
How can I set an array's size at run time? How can I avoid
fixed-sized arrays?
How can I declare local arrays of a size matching a
passed-in array?
How can I dynamically allocate a multidimensional array?
How do I write functions which accept two-dimensional arrays
when the width is not known at compile time?
How can I use statically- and dynamically-allocated
multidimensional arrays interchangeably when passing them to
functions?
Why doesn't sizeof properly report the size of an array
when the array is a parameter to a function?
Why doesn't this fragment work?
char *answer;
printf("Type something:\n");
gets(answer);
printf("You typed \"%s\"\n", answer);
I just tried the code
char *p;
strcpy(p, "abc");
and it worked. How? Why didn't it crash?
How much memory does a pointer variable allocate?
Why am I getting "warning: assignment of pointer from
integer lacks a cast" for calls to malloc()?
Why does some code carefully cast the values returned by
malloc to the pointer type being allocated?
Why isn't a pointer null after calling free()? How unsafe is
it to use (assign, compare) a pointer value after it's been
freed?
When I call malloc() to allocate memory for a pointer which
is local to a function, do I have to explicitly free() it?
I'm allocating structures which contain pointers to other
dynamically-allocated objects. When I free a structure, do
I also have to free each subsidiary pointer?
Must I free allocated memory before the program exits?
How does free() know how many bytes to free?
Can I query the malloc package to find out how big an
allocated block is?
Is it legal to pass a null pointer as the first argument to
realloc()?
What's the difference between calloc() and malloc()? Is it
safe to take advantage of calloc's zero-filling? Does
free() work on memory allocated with calloc(), or do you
need a cfree()?
What is alloca() and why is its use discouraged?
Why doesn't
strcat(string, '!');
work?
How can I get the numeric (character set) value
corresponding to a character, or vice versa?
What is the right type to use for Boolean values in C?
Is if(p), where p is a pointer, a valid conditional?
How can I write a generic macro to swap two values?
What's the best way to write a multi-statement macro?
Is it acceptable for one header file to #include another?
What's the difference between #include <> and #include "" ?
What are the complete rules for header file searching?
How can I construct preprocessor #if expressions which
compare strings?
Does the sizeof operator work in preprocessor #if directives?
Can I use an #ifdef in a #define line, to define something
two different ways?
Is there anything like an #ifdef for typedefs?
How can I use a preprocessor #if expression to tell if a
machine is big-endian or little-endian?
How can I list all of the predefined identifiers?
How can I write a macro which takes a variable number of
arguments?
What is the "ANSI C Standard?"
What's the difference between "const char *p" and "char *
const p"?
Why can't I pass a char ** to a function which expects a
const char **?
What's the correct declaration of main()?
Can I declare main() as void ?
What does the message "warning: macro replacement within a
string literal" mean?
What are #pragmas and what are they good for?
What does "#pragma once" mean?
Is char a[3] = "abc"; legal? What does it mean?
Why can't I perform arithmetic on a void * pointer?
What's the difference between memcpy() and memmove()?
What should malloc(0) do? Return a null pointer or a
pointer to 0 bytes?
What's wrong with this code?
char c;
while((c = getchar()) != EOF) ...
Why does the code
while(!feof(infp)) {
fgets(buf, MAXLINE, infp);
fputs(buf, outfp);
}
copy the last line twice?
How can I read one character at a time, without waiting for
the RETURN key?
How can I print a '%' character in a printf format string?
What printf format should I use for a typedef like size_t
when I don't know whether it's long or some other type?
How can I implement a variable field width with printf?
How can I print numbers with commas separating the
thousands? What about currency formatted numbers?
Why doesn't the call scanf("%d", i) work?
How can I specify a variable width in a scanf() format string?
Why doesn't this code:
double d;
scanf("%f", &d);
work?
How can I tell how much destination buffer space I'll need
for an arbitrary sprintf call? How can I avoid overflowing
the destination buffer with sprintf()?
What's the difference between fgetpos/fsetpos and ftell/fseek?
What are fgetpos() and fsetpos() good for?
How can I redirect stdin or stdout to a file from within a
program?
How can I read a binary data file properly?
How can I convert numbers to strings (the opposite of
atoi)? Is there an itoa() function?
Why does strncpy() not always place a '\0' terminator in the
destination string?
Why do some versions of toupper() act strangely if given an
upper-case letter?
How can I split up a string into whitespace-separated
fields? How can I duplicate the process by which main() is
handed argc and argv?
How can I sort a linked list?
How can I sort more data than will fit in memory?
How can I get the current date or time of day in a C program?
How can I add N days to a date? How can I find the
difference between two dates?
How can I get random integers in a certain range?
How can I generate random numbers with a normal or Gaussian
distribution?
What does it mean when the linker says that _end is undefined?
When I set a float variable to, say, 3.1, why is printf
printing it as 3.0999999?
What's a good way to check for "close enough"
floating-point equality?
How do I round numbers?
Why doesn't C have an exponentiation operator?
How do I test for IEEE NaN and other special values?
What's a good way to implement complex numbers in C?
How can %f be used for both float and double arguments in
printf()? Aren't they different types?
How can I write a function that takes a variable number of
arguments?
How can I write a function that takes a format string and a
variable number of arguments, like printf(), and passes them
to printf() to do most of the work?
How can I write a function analogous to scanf(), that calls
scanf() to do most of the work?
How can I discover how many arguments a function was
actually called with?
How can I write a function which takes a variable number of
arguments and passes them to some other function (which
takes a variable number of arguments)?
How can I call a function with an argument list built up at
run time?
C QUESTIONS
What does static variable mean?
What is a pointer?
What is a structure?
What are the differences between structures and arrays?
In header files whether functions are declared or defined?
What are the differences between malloc() and calloc()?
What are macros? what are its advantages and disadvantages?
Difference between pass by reference and pass by value?
What is static identifier?
Where are the auto variables stored?
Wher
declare an array of structure where the members of the
structure are integer variable float variable integer array
char variable access all elements of the structure using dot
operator and this pointer operator
total amount of milk produced each morning and then calculates
and outputs the number of cartons needed for this milk , the
cost of producing the milk and the profit from producing this
milk.
Board Coloring
Problem Description
In this problem you are given a board in which some of the
elements are placed as shown in diagram below. Each element
represents a color. Fill the other elements in the board,
such that none of the adjacent elements (vertically,
horizontally and diagonally) should be of the same color.
Find out the minimum number of colors that should be used to
fill the blank spaces in the board, so that the above
condition is met. Color representation is -: 0, 1, 2, 3, 4,
5, 6, 7 . There is sample board:
For Example:
Given Board :
Matrix representation of board is : [ _ 1 _ _ ] [ 2 _ _ _ ]
[ _ _ 2 _ ] [ 2 _ _ _ ] here blank space is represented by
'_' . Minimum colors to fill this board (given in the
picture)is 4.
Instruction to work with Open PBT Client:
Specify the work directory path in the 'Work directory Path'
field. The path should correspond to your solution Work
directory.
Download the support files by clicking the Get Dev Files.
You will find the problem directories containing:
problem.h file
problem.c file
in your project directory.
Code the solution in.c file inside the problem directory
All required files will be downloaded to your work
directory. Creating additional files is strongly discouraged.
Step 1:
In your Solution File:
Implement your logic in function int color(char board[4][4])
char board[4][4]board is 2 dimensional matrix of order M X
M where M = 4.
You can create more functions if required, but those
functions should be in the same file.
Step 2:
In your solution keep in mind the following constraints.
In this problem you have to write a program that finds the
minimum number of colors needed to fill a board in which
some of the elements are placed in advance.
Function color() will take 2 dimension board as a input.
Function color() returns the minimum number of colors that
could fill the board meeting the given condition.
Board is a 2 dimensional of M X M where M = 4 else return 0
Fill the other elements in the board, such that none of the
adjacent elements (vertically, horizontally and diagonally)
should be of the same color.
The Prototype of the function is
int color(char board[4][4]) This function takes following
arguments.
board is 2 dimensional matrix of order M X M where M = 4.
This function returns minimum no of color by which board can
be filled.
The constraints are:
Board is a 2 dimensional of M X M where M = 4 else return 0
Fill the other elements in the board, such that none of the
adjacent elements (vertically, horizontally and diagonally)
should be of the same color.
Example 1
Input { 2 0 _ 1 } { _ 1 _ _ } { _ 2 _ 0 } { _ _ _ 1 }
Output 5 Explanation: We need a minimum 5 different colors
to complete the board.
Example 2
Input { 2 0 _ 1 3} { _ 1 _ _ 2} { _ 2 _ 0 1} { _ _ _ 1 2} {
_ _ _ _ 0}
Output 0 Explanation: Size of the board is greater than 4X4.
Example 3
Input { _ 0 } { 1 _ }
Output 0 Explanation: Size of the board is less than 4X4.
For C solutions
Header File
:
boardcoloring.h
Function Name
:
int color(char board1[4][4])
File Name
:
boardcoloring.c
For C++ solutions
Header File
:
boardcoloring.h
Class Name
:
BoardColoring
Function Name
:
int color(char board1[4][4])
File Name
:
boardcoloring.c
write a program that will produce the ff. output.
"what fruit will you buy?
1)apple
2)orange
3)mango
ENTER CHOICE (1,2 or 3)>
HOW MANY WILL YOU BUY?>
THAT WILL COST XX.XX
class base
{
public:
int fun(int)
{}
};
class base2
{
public:
int fun(float)
{
}
};
so here qustion is both function either function
overloading or over riding;
Visual Basic 6
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q1. A. Discuss the various types of variables.
B. How to control the file?
Q2. A. How the image application?
B. Write short notes on trees structures work.
Q3. A. How to load and unload child forms.
B. When should we use recursive programming
Q4. A. Write short notes on "The ole control's shortcut
menu"
B. How to test the AX stat class
Q5. A. How to use advanced data-bound controls.
B. Write notes on manipulating the recordset object
Q6. A. What is script control?
B. How to down load image properties.
C. What is meant by building a recordset.
PROJECT 2002
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q1. A. How can we determine performance standards?
B. Write note on chaining views.
Q2. A. Discuss the working with task in Gantt chart view.
B. Explain the creation project schedule.
Q3. A. What is understand in resource tracking?
B. Write short notes on Caturing Baseline.
Q4. A. How to customize workgroup message?
B. How to use hyperlink?
Q5. A. Explain the installation of project server?
B. Discuss the working with to-do lists.
Q6. A. Explain the working of templates?
B. What is visual basic?
C. Write shortnotes on user forms.
PROGRAMMING WITH C++
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q1. A. What is unary operator? List out the different
operators involved in the unary operator.
B. What is an adjust field format flag?
Q2. A. Distinguish between a # include and #define.
B. Can a list of string be stored within a two dimensional
array?
Q3. A. Explain how a pointer to function can be declared in
C++?
B. List the merits and demerits of declaring a nested class
in
C++?
Q4. A. What are the syntactic rules to be avoid ambiguity
in multiple
inheritence?
B. Explain the operation of overloading of an assignment
operator.
Q5. A. Explain how the virtual base class is different from
the
conventional base classes of the opps.
B. Explain how an exception handler is defined and invoked
in a
Program.
Q6. A. What is a binary file? List the merits and demerits
of the binary
file usagein C++.
B. Write short notes on Text Manipulation Routines.
C. Write bites in Turbo c++ Header ("Include") Files.
Java
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q1. A. Write note on "The class path Environment Variable".
B. Which are different kinds of source code?
Q2. A. How to create an interface?
B. Why convert an applet to an application?
Q3. A. How to use Media tracker Class.
B. How to use string tokenizer class.
Q4. A. Explain the overview of UDP messaging.
B. Difference between SQL Exception class and SQL Warning
class.
Q5. A. How to create com object in Java?
B. Write short notes on "The properties class"
Q6. A. When object is created and destroyed?
B. Explain the JDB in depth & command line.
C. Write short notes on Web Sites.
MULTIMEDIA
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q.1 Write a C language program to perform CCITT group 3
compression. If possible, scan some images and use your
program to compress the images. What kind of compression
did you achieve?
Q2. How does a magneto-optical technology differ from WORM
technology? Explain the differences in the manner in which
you would use them for a multimedia system.
Q3. What network considerations would you contemplate in
designing an enterprise-wide multimedia system which
supports fully distributed integrated messaging, sharing of
corporate multimedia information databases, and custom
business process applications?
Q4. Explain the difference between the various types of
multimedia object servers. How would you set up
hierarchical storage for a large distributed organization?
Q5. Explain the role of each type of server required in a
multimedia system and the type of storage media that should
be used for it.
Q6. How do your decisions affect the design? Would
different decisions on network technologies and object
server technologies result in a different solution?
OPERATING SYSTEM
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q1. What is an interrupt? How are multiple interrupts dealt
with?
Q2. Explain the difference between a MONOLITHIC KERNAL and
a MICROKERNAL?
Q3. List reasons why a Mode switch between threads may be
cheaper than a Mode switch between processes.
Q4. What is the difference among deadlock avoidance,
detection and prevention?
Q5. What items of information about a task might be useful
in real time scheduling?
Q6. Discuss some of the reasons for implementing process
migration ?
How is the process address space handled during process
migration?
WEB APPLICATIONS
All the questions are compulsory. The first five questions
shall be of 16 marks each and the last question shall be of
20 marks.
Q1. Explain Java script in Web pages?
Q2. Explain the advantages of Java script.
Q3. Write the Properties of HTML object.
Q4. How a JavaScript enabled browser handles the document
object?
Q5. What are cookies?
Q6. Explain the process of controlling the Program flow in
Pearl.
declare an array of structure where the members of the
structure are integer variable float variable integer array
char variable access all elements of the structure using dot
operator and this pointer operator
125
Write a program which is required to process the time of a
clock in hours and minutes, entered from the keyboard. With
this program, there are two requirements for any data
entered by a user:
1. The data must be of the correct type (in this case, two
ints).
2. The data must be in the correct range: this means that,
for the minutes, negative numbers and any number above 59
must be rejected; for the hours, negative numbers and any
number above 23 must be rejected.
Output error message for invalid data input.
Output the time one and a half hour after the time input.
i.e.
Hour: 22
Min: 32
One and a half hour after 22:32 is 00:02
109
write a program that reads in a file and counts the number
of lines, words, and characters. Your program should ask the
user to input a filename. Open the file and report an error
if the file does not exist or cannot be opened for some
other reason.
Then read in the contents of the file and count the number
of lines, words, and characters in the file. Also print
additional information about the file, such as the longest
and shortest words, and longest and shortest lines. For
simplicity, we define a word to be one or more characters
ending with white space (a space, tab, carriage return,
etc.). Functions for checking the types of characters can be
found in the ctype.h header file, so you want to include
this header file in your program.
For example, the sentence below could be all that is in a
file. This sentence
IT 104 is taught in C++.
has 32 characters, one line, and six words. The shortest
line is 32 characters. The longest line is 32 characters.
The shortest word is 2 characters. The longest word is 6
characters
690
A mXn matrix is given and rows and column are sorted as
shown below.Write a function that search a desired entered
no in the matrix .with minimum complexity
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
401
Snake Game: This is normal snake game which you can find in
most of
the mobiles. You can develop it in Java, C/C++, C# or what ever
language you know.
284
Write a program to read the data and evaluate the results of
the election. Print all output to the screen.
Your output should specify:
The total number of votes, the number of valid votes and the
number of spoilt votes.
The winner(s) of the election. Hint: An appropriate search
should be used to determine the winner(s).
The votes obtained by each candidate sorted in terms of the
number of votes obtained. Hint: An appropriate sort should
be used to sort the candidate(s).
The Source code should be saved as VotingSystem.
Project Input:
Candidates Names and Numbers
2501 Victor Taylor
2502 Denise Duncan
2503 Kamal Ramdhan
2504 Michael Ali
2505 Anisa Sawh
2506 Carol Khan
2507 Gary Owen
Votes
3 1 2 5 4 3 5 3 5 3 2 8 1 6 7 7 3 5 6 9 3 4 7 1 2 4 5 5 1 4 0
Project Output:
Invalid vote: 8
Invalid vote: 9
Number of voters: 30
Number of valid votes: 28
Number of spoilt votes: 2
The winner(s):
2503 Kamal Ramdhan
2505 Anisa Sawh
Candidate Score
2503 Kamal Ramdhan 6
2505 Anisa Sawh 6
2501 Victor Taylor 4
2504 Michael Ali 4
2502 Denise Duncan 3
2507 Gary Owen 3
2506 Carol Khan 2
251
write a porgram in c++ that reads an integer and print the
biggest digit in the number
100
Arrange Doubly linked list in the ascending order of its
integral value and replace integer 5 with 7?