Vous êtes sur la page 1sur 48

******************* General Question Paper ***********************

1). Declaration of a variable does not give which one of the following
a) Size of the variable b) Scope of the variable
c) Type of the variable d) Allocates memory for the variable
ans :d
2) Same name can't be given to two variables
a) Within a function b) Across two files
c) Within a block d) Within a program
ans :c
3) The hexa value FEDB when converted to octal gives
a)177333 b) 770333 c) 751233 d) 378453
ans :a
4) In 8 bit representation using sign bit, the minimum number is
a)-128 b) -127 c) -255 d) 0
ans:a
Output of the following:
************************************************************
5)
f(int x)
{
if(x<=0) return 1;
return f(x-1) + x;
}
void main()
{
printf("%d",f(7));
}
a) 28 b) 29 c) 15 d) None
ans :b
************************************************************
6)
main()
{
int i;
printf ("%d",i);
}
a)syntax error b)God alone knows c)0 d)65535
************************************************************
7)
int i;
main()
{
printf ("%d", i );.}
a)syntax error b)God alone knows c)0 d)65535
************************************************************
8)
main()
{
int i;
while ()
{ int i;
printf ("%d..", i );
i--;
}
}
a)infinite loop b)error c)3..2..1 d)none
************************************************************
9)
void main()
{
int x=8;
x=x>10?x<<2:x>7?x>>2:x<<3;
printf("%d",x);
}
a) 1 b) 2 c) 4 d) None
************************************************************
10)
main()
{
{
{
}
}
}
a)no output b)compilation error c)warning of fn. should return a value
d)system hangs.
************************************************************
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
Some of the C frequently asked questions (Collected from Express
Computer mag.)
1. what is the error in the following sequence of program.
int i1;
switch(i1)
{
printf("The value of I1 is :");.case 1: printf("%d",i1);
break;
case 2: printf("%d",i1);
break;
default : printf("Invalid entry");
}
************************************************************
2. what is an error in the following sequence of a program.
int i1;
switch(i1)
{
case 1: goto lure;
break;
case 2: printf("This is second choice");
break;
default: printf("This is default choice");
}
void fun(void)
{
lure: printf("This is unconditional jump");
}error : undefined symbol lure.
************************************************************
3. What is an error in the following sequence of a program.
int i;
switch(i)
{
case 1: printf("This is first choice");
break;
case j: printf("This is second choice");
break;
case 1+2+4: printf("This is the third and last choice");
break;
}
ERROR
************************************************************
4. what is an error in the following sequence of a program.
int i;
switch(i)
{
default: printf("This is default value");
break;
case 1: printf("This is first choice");
break;
case 2: printf("This is the second choice");
}.NO ERROR
************************************************************
1. Will the following be used as an identifier?
a. sum_of_credits b. initial tree c. final_#
d. while e. SECTION_6 f. bingo-square
g. 2_4_87
************************************************************
2. Are the identifiers name and NAME are same?no
************************************************************
3. Is it right to type # of #define other than in first column?
************************************************************
4. Does C require expressions to be enclosed in parenthesis for while loop?
s
************************************************************
5. Will the preprocessor terminates with semicolon ? no
************************************************************
6. What is the return value of scanf statement? No:of inputs received
************************************************************
7. What will happen, if there are two statements (without grouping) in if
condition and an else is there for that if. Error : Misplaced else in function
main
************************************************************
8. What will be the output of this program.
int no_fish;
no_fish=1;
if (no_fish==1)
printf("The water was to warm\n");
else ;
printf("The wates were all fished out\n");
Is parenthesis required for conditional expression in if condition? yes
************************************************************
///////////////
C questions from Citycorp .
************************************************************
1
main()
{
int x=10,y=15;.x=x++;
y=++y;
printf("%d %d\n",x,y);
}11 16
************************************************************
2
int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output: %d\n",x);
}
x++;
change_value(x);
printf("Second Output : %d\n",x);
Modify_value();
printf("Third Output : %d\n",x);
}
Modify_value() { return (x+=10); }
Change_value() { return(x+=1); } 12 1 1
*
***********************************************************
3.
main()
{
int x=20,y=35;
x = y++ + x++; x=56 y=36
y = ++y + ++x; y=94 x=57
printf("%d %d\n",x,y);
}
************************************************************
4
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);.}No output
************************************************************
5.
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x2);
}
************************************************************
6
#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;
}
************************************************************
7
main()
{
char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
Samco systems
amco systems
************************************************************
8
#include<stdio.h
main()
{
char s1[]="Ramco";.char s2[]="Systems";
s1=s2;
printf("%s",s1);
} ERROR
************************************************************
9.
#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);
}
************************************************************
///////////////////////////////////////////////////////////////////////////////////
//////////////////
DESHAW softwares
THIS PAPER HAS GIVEN IN IIT DELHI , SO GO THROUGH THIS
IT WILL GIVE
ROUGH IDEA;
1. typedef struct{
char *;
nodeptr next;
} * nodeptr;
what does nodeptr stand for? struct *
************************************************************
2. supposing thaty each integer occupies 4 bytes and each charactrer 1 byte,
what is the output of the following programme?
#include<stdio.h
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d\t %d ", (&a[3]-&a[0]),(&c[3]-&c[0]));
}
ans : 3 3
2. supposing thaty each integer occupies 4 bytes and each charactrer 1 byte,
what is the output of the following programme?.#include<stdio.h
main()
{
int a[] ={ 1,2,3,4,5,6,7};
char c[] = {' a','x','h','o','k'};
printf("%d\t %d ", ((int)&a[3]-(int)&a[0]),(&c[3]-&c[0]));
}
ans : 12 12
************************************************************
3. what is the output of the program?
#include<stdio.h
main()
{
struct s1 {int i; };
struct s2 {int i; };
struct s1 st1;
struct s2 st2;
st1.i =5;
st2 = st1;
printf(" %d " , st2.i);
}
CHECK: ans: error. expl: diff struct variables should not assigned
using "=" operator.
************************************************************
4.what is the output of the program?
#include<stdio.h
main()
{
int i,j;
int mat[3][3] ={1,2,3,4,5,6,7,8,9};
for(i=2;i=0;i--)
for(j=2;j=0;j--)
printf("%d" , *(*(mat+j)+i));
}
ans : 9 6 3 8 5 2 7 4 1
************************************************************
5.int fun( int n)
{
int i;
for(i=0;i<=n;i++)
fun(n-i);
printf(" well done");
}
howmany times is the printf statement executed for n=10?.ans: zero
expl: Befire reaching to printf statement it will goes to infinite loop.
************************************************************
6.what is the output of the program?
main()
{
struct emp{
char emp[];
int empno;
float sal;
};
struct emp member = { "TIGER"};
printf(" %d %f", member.empno,member.sal);
}
ans: error. In struct variable emp[], we have to give array size. If array size
given ans is 0, 0.00
************************************************************
7. output of the program?
# define infiniteloop while(1)
main()
{
infiniteloop;
printf("DONE");
}
ans: none
expl: infiniteloop in main ends with ";" . so loop will not reach end;
and the DONE also will not print.
************************************************************
8. output of the program?
main()
{
int a=2, b=3;
printf(" %d ", a+++b);
}
ans:5
expl: here it evaluates as a++ + b.
************************************************************
9. output of the program?
#define prn(a) printf("%d",a)
#define print(a,b,c) prn(a), prn(b), prn(c)
#define max(a,b) (a<b)? b:a
main()
{
int x=1, y=2;.print(max(x++,y),x,y);
print(max(x++,y),x,y);
}
ans: 2 2 2 3 4 2
************************************************************
10. which of the following is the correct declaration for the function main()
?
ans: main( int , char *[])
************************************************************
11. if ptr is defined as
int *ptr[][100];
which of the following correctly allocates memory for ptr?
ans: ptr = (int *)(malloc(100* sizeof(int));
**********************************************************
1.while((*p++=*q++)!=0){}
is equal to
expl: while((*p++=*q++)!='\0'){}
a) b) c) d)
...........................................................
************************************************************
2.the function strcmp(str1,str2) returns
ans: int
...........................................................
************************************************************
3. int *x[](); means expl: Elments of an array can't be functions.
...........................................................
************************************************************
4.#define PRINT(int) printf("int=%d",int);
main()
{
int x,y,z;
x=03;y=-1;z=01;
PRINT(x^x);
z<<=3;PRINT(x); ---- I think here may be (z). for this ans=8.
if (x) ans ix =3.
y=3;PRINT(y);
}
expl: 0,8,-1 (if second is z)
..........................................................
************************************************************.5. struct list
{
int x;
struct list *next;
}*head;
the struct head.x =100
above is correct / wrong
expl: Before using the ptr type struct variable we have to give memory
to that. And also when ever the struct variable is ptr then we access the
members by "-" operator.
.........................................................
************************************************************
6. '-'=45 '/'=47
printfr(%d/n,'-','-','-','-','/','/','/');
o/p =?
ans: 45 ( i.e it takes first argument in printf function.
.........................................................
************************************************************
7.o/p=?
int i;
i=1;
i=i+2*i++;
printf(%d,i);
ans: 4
.........................................................
************************************************************
8.{
ch='A';
while(ch<='F'){
switch(ch){
case'A':case'B':case'C':case'D':ch++;continue;
case'E':case'F':ch++;
}
putchar(ch);
}
} a)ABCDEF b.EFG c.FG d.error
ans: c
..........................................................
************************************************************.9. FILE *fp1,*fp2;
fp1=fopen("one","w")
fp2=fopen("one","w")
fputc('A',fp1)
fputc('B',fp2)
fclose(fp1)
fclose(fp2)}
a.error b. c. d.
ans: no error. But It will over writes on same file.
..........................................................
************************************************************
10. int a=1, b=2, c=3, *pointer;
pointer=&c;
a=c/*pointer;
b=c;
printf("a=%d b=%d",a,b);
a. a=1 b=3
b a=3 b=3
c 3 2
d. error
ans: d . Because ";" indicates competion of that statement. so It give error.
* Imp: And in above program " a=c/*pointer " statement it considering as
starting of comment statement. So , It also causing for syntax error.
...........................................................
************************************************************
11.#include<malloc.h
char *f()
{char *s=malloc(8);
strcpy(s,"goodbye")}
main()
{
char *f();
printf("%c",*f()='A');
o/p=?
ans: prints " A "
............................................................
************************************************************
12. int sum(n)
int n;
if(n<1)return n;
else return(n+sum(n-1)).a 10 b 16 c 14 d 15
ans: If we take n=5 then ans is 15.
............................................................
************************************************************
13. when a function is recursively called all ,
automatic variables are a. stored in stack b . c. d
ans: (a)
............................................................
************************************************************
14) #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)}
............................................................
************************************************************
15) a=10;b=5; c=3;d=3;
if(a<b)&&(c=d++)
printf(%d %d %d %d a,b,c,d)
else printf("%d %d %d %d a,b,c,d);
......................................................
************************************************************
16. what is o/p
#include<stdarg.h
show(int t,va_list ptr1)
{
int a,x,i;
a=va_arg(ptr1,int)
printf("\n %d",a)
}
display(char)
{int x;
listptr;
va_star(otr,s);
n=va_arg(ptr,int);
show(x,ptr);
}
main()
{.display("hello",4,12,13,14,44);
}
a) 13 b) 12 c) 44 d) 14
.............................................
************************************************************
17. if the following program (my prog)
main(int size of ,char *arg[])
{ while(size of arg) printf("%s",arg[--size of arg)
}
is run from the command line as myprog jan feb mar apr
what would be the o/p
a)myprog jan,feb,mar,apr
b)rev
c)jan,feb,mar,apr
d)error
.............................................
************************************************************
18.what is o/p
main()
{int i=3;
while(i--)
{
int i=100
i--;
printf("%d..",i);
}
}
a) infinite loop
b) error
c) 99..99..99..99
d) 3..22..1..
..........................................................
************************************************************
19)what is the o/p of the program
main()
{
int rows=3,colums=4;
int a[rows][colums]={1,2,3,4,5,6,7,8,9,10,11,12};
i=j=k=99;
for(i=0;i<rows;i++)
for(j=0;j<colums;j++)
if(a[k][j]<k) k=a[i][j];
printf("%d\n",k);...............................................
************************************************************
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////
EASI-TECH(96)
WRITE THE OUTPUT FOR FOLLOWING PROGRAMS.
1) printf("%d%x\n",ox2,12);
************************************************************
2) int a=10;
int b=20;
a=a^b;
b=a^b;
a=a^b;
printf("%d%d\n",a,b);
************************************************************
3)enum {ELLIPSE, TRIANGLE, RECTANGLE, SQUARE=100,
CIRCLE=5}
printf{"%d%d%d%d\n",TRIANGLE-RECTANGLE,SQUARE*CIRCLE-RECTANGLE};
************************************************************
4) define the following...
a) pointer to a integer
b) pointer to a char
c) function pointer returning a pointer integer.
************************************************************
5) void a(void);
main() { a(); }
void a(void)
{
char a="HELLOW";
char *b="HELLOW";
char c[10]="HELLOW";
printf("%s%s%s\n",a,b,c);
printf("%d%d%d\n",sizeof(a),sizeof(b),sizeof(c)));
}
************************************************************
6) int a=15;
int b=16;
printf("%d %d \n",a&b,a/b); (bitwise
operators).************************************************************
7) int a[5],*p;
for(p=a;p<&a[5];p++)
{
*p=p-a;
printf("%d\n",*p);
}
************************************************************
8) scanf("xyz abc ABC 345" "% *[a-z A-Z]lf",&a);
printf("lf",a);
************************************************************
9) main()
{
int i=10;
printf("%d",i);
{
int i=20;
printf("%d",i);
}
printf("%d",i);
}
************************************************************
10)struct class
{
int i;
float a;
string[12];
}
sizeof(class)=?
************************************************************
11) int *p;
i=10;
p=i;
printf("%d",*p);
************************************************************
12) fact(5)
int n;
fact(n)
{.sum=n*fact(n-1);
}
************************************************************
C QUESTIONS:WHAT IS THE OUT PUT FOR FOLLOWING
PROGRAMMS
1)main()
{
char a[2];
*a[0]=7;
*a[1]=5;
printf("%d",&a[1]-a)
ANS: may be 1.(illegal initialization)
************************************************************
2)#include<stdio.h
main(){
char a[]="hellow";
char *b="hellow";
char c[5]="hellow";
printf("%s %s %s ",a,b,c);
printf(" ",sizeof(a),sizeof(b),sizeof(c));
}
(ans is hellow,hellow,hellow 6,2,5 )
************************************************************
3)#include<stdio.h
main(){
float value=10.00;
printf("%g %0.2g %0.4g %f",value,value,value,value)
}
(ans is 10,10,10,10.000000)
************************************************************
4)#include<stdio.h
void function1;
int i-value=100;
main()
{
i-value=50;
function1;
printf("i-value in the function=",i-value);
printf("i-value after the function=",i-value);
}.printf("i-value at the end of main=",i-value);
functioni()
i-value=25;
THIS IS ROUGH IDEA OF THE PROGRAM
ANS ARE
1)i-value in the function=25;
2)i-value after the function=50;
3)i-value at the end of the main=100;
************************************************************
5)main()
{
funct(int n);
{
switch(n)
case1:
m=2;
break;
case2:
m=5;
break;
case3:
m=7;
break;
default:
m=0;
}
THIS IS ROUGH IDEA:
(ANS:Out put is m=0)
************************************************************
///////////////////////////////////////////////////////
GEMET
1)a=0; b=(a=0)?2:3;
a) What will be the value of b? why
b) If in 1st stmt a=0 is replaced by -1, b=?
c) If in second stmt a=0 is replaced by -1, b=?
************************************************************
2)f()
{
int a=2;
f1(a++);.}
f1(int c)
{
printf("%d", c);
}
c=?
************************************************************
3)f1()
{
f(3);}
f(int t)
{
switch(t);
{
case 2: c=3;
case 3: c=4;
case 4: c=5;
case 5: c=6;
default: c=0;} value of c?
************************************************************
4)Fallacy
int *f1()
{
int a=5;
return &a;
}
f()
int *b=f1()
int c=*b;
}
************************************************************
5)a)Function returning an int pointer
b)Function ptr returning an int ptr
c)Function ptr returning an array of integers
d)array of function ptr returning an array of integers
(See Scham series book)
************************************************************
6)fallacy
int a;
short b;
b=a;.************************************************************
7)Define function ?Explain about arguments?
************************************************************
8)C passes By value or By reference?
************************************************************
9)Function which gives a pointer to a binary trees const an integer value at
each code, return function of all the nodes in binary tree.
(Study)Check
************************************************************
10)Calling refernce draw the diagram of function stack illustrating the
variables in the -----then were pushed on the stack at the point when
function f2 has been introduced
type def struct
{ double x,double y} point;
main( int argc, char *arg[3])
{double a;
int b,c;
f1(a,b);}
f1(double x, int y)
{
point p;
stack int n;
f2(p,x,y)}
f2(point p, double angle)
{ int i,j,k,int max)
}
************************************************************
////////////////////////////////////////////////////////////
HCL Tech.1999-2000
1)which is a ternary operator?
a)? B)+ c)sizeof d)^ e)~ ans.: a
************************************************************
2)which is logical operator?
1)&& 2)|| 3)! 4)^
a)1 only B)2 only c)1,2,4 only e)1,2,3 ans : e
************************************************************
3) which is not bitwise operator?.a)^ B)~ c)! d)|| e)& ans. : d
************************************************************
4)
f(int x)
{
if(x<=0) return 1;
return f(x-1) + x;
}
void main()
{
printf("%d",f(5));
}
a) 16 b) 15 c) 5 d) None ans. : a
************************************************************
5)short *p[4]
memory allocated for the above
a)none B)2 c)4 d)16 e)6 ans.:
************************************************************
6)which is true?
main(char argc, char *argv[])
main(int argc, int *argv[])
c) main(int *argc, char *argv[])
d) main(int argc, char *argv[])
e) main(int argc, char argv[])
ans. : d
************************************************************
7) sizeof the following segment is
union x
{
int j;
char y[8];
int a[4];
char k;
} xy;
a) 29 b)19 c)8 d)20 ans. : c
************************************************************
PROGRAM ANALYSIS
1)
#define NULL 0.char * f(str,c)
register char * str,c;
{
while(*str)
if(*str++ == c) return str;
return NULL;
}
the above function will always work
a)always b) won't work for c = NULL
c) won't work if c is not found
d) won't work if c is the first character ans. : a
************************************************************
2)main()
{printf("%d",f(7));
}
f(x)
{if (x<=4)
return(x);
return f(--x);
}
a) 5 b) 4 c) 6 d) 8
************************************************************
3) in a system where the size of a pointer is 4 bytes.
#define NULL 0
void main()
{
int i=0,*p = NULL;
i++;p++;
printf("%d %d",i,p);
}
a) 1 4 b) 4 1 c) 4 4 d)1 1 ans. : a
************************************************************
////////////////////////////////////////////////////////////
HEXAWARE SOFTWARES
main()
{
int a[]={ 2,4,6,8,10 };
int i;
change(a,5);
for( i = 0; i <= 4; i++)
printf("\n %d",a[i]);.}
change( int *b, int n){
int i;
for( i = 0; i < n; i++)
*(b+i) = *(b+i) + 5;
}
************************************************************/
///////////////////////////////////////////////////////////
c QUESTIONS FROM NOVEL
1.Max value of SIGNED int
************************************************************
2.One questin is given, long one, to find the answer U should be femiliar
with the operation as follows
int *num={10,1,5,22,90};
main()
{ int *p,*q;
int i;
p=num;
q=num+2;
i=*p++;
print the value of i, and q-p, and some other operations are there.
}
how the values will change??
************************************************************
3. One pointer diff is given like this:
int *(*p[10])(char *, char*)
asked to find the meaning.
************************************************************
4. char *a[4]={"jaya","mahe","chandra","buchi"};
what is the value of sizeof(a)/sizeof(char *)
a. 4 b.bytes for char c-- d.--
( we don't know the answer)
************************************************************
5. void fn(int *a, int *b)
{
int *t;
t=a;
a=b;
b=t;
}.main()
{
int a=2;
int b=3;
fn(&a,&b);
print the values os a and b;
}
what is the output--- out put won't swap, the same values remain.
a. error at runtime
b. compilation error
c.2 3
d. 3 2
************************************************************
6.#define scanf "%s is a string"
main()
{
printf(scanf,scanf);
}
what is the output. ANS : %s is a string is string
************************************************************
7. i=2+3,43,1;
printf("%d"i);
ans is 5 only.
************************************************************
8. char *p="abc";
char *q="abc123";
while(*p=*q)
{
print("%c %c",*p,*q);
}
a. aabbcc
b. aabbcc123
c. abcabc123
d. infinate loop ( this may be correct)
************************************************************
9. printf("%u",-1). what is the value?
a. -1 b. 1 c. 65336 d. --
(maxint value-1 I think, check for the
answer).************************************************************
10. #define void int
int i=300;
void main(void)
{
int i=200;
{
int i=100;
print the value of i;
}
print the value of i
}
what is the output?
may be 100 200
************************************************************
11.int x=2;
x=x<<2;
printf("%d ",x);
ANS=8;
************************************************************
12. int a[]={0,0X4,4,9}; /*some values are given*/
int i=2;
printf("%d %d",a[i],i[a]);
what is the value??? (may be
error)
ANONYMOUS
void *ptr;
myStruct myArray[10];
ptr = myArray;
Which of the following is the correct way to increment the variable "ptr"?
Choice 1
++(int*)ptr;
Choice 2
ptr = ptr + sizeof(myStruct);
Choice 3
ptr = ptr + sizeof(myArray);
Choice 4.increment(ptr);
Choice 5
ptr = ptr + sizeof(ptr);
************************************************************
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////
TISL - C QUESTIONS
1). what will be the result of executing following program
main
{
char *x="new";
char *y="dictonary";
char *t;
void swap (char * , char *);
swap (x,y);
printf("(%s, %s)",x,y);
char *t;
t=x;
x=y;
y=t;
printf("-(%s, %s)",x,y);
}
void swap (char *x,char *y)
{
char *t;
y=x;
x=y;
y=t;
}
a).(New,Dictionary)-(New,Dictionary)
b).(Dictionary,New)-(New,Dictionary)
c).(New,Dictionary)-(Dictionary,New)
d).(Dictionary,New)-(Dictionary,New)
e).None of the above
(Ans will be b or e) check
************************************************************
2) what would the following program results in
main()
{
char p[]="string";
char t;.int i,j;
for(i=0,j=strlen(p);i<j;i++)
{
t=p[i];
p[i]=p[j-i];
p[j-i]=t;
}
printf("%s",p);
}
a)will print:string
b)will not print anything since p will be pointing to a null string
c)will print:gnirtS
d)will result in a complication error
e)will print invallid characters(junk)
(Ans will be b ) check
************************************************************
3) What will be the result of executing the following statement
int i=10;
printf("%d %d %d",i,++i,i++);
a).10 11 12
b).12 11 10
c).10 11 11
d).result is OS dependent
e).result is compiler dependent
(Ans is e)
************************************************************
4) What will be result of the following program
main()
{
void f(int,int);
int i=10;
f(i,i++);
}
void f(int i,int j)
{
if(i>50)
return;
i+=j;
f(i,j);
printf("%d,",i);
}
a).85,53,32,21
b)10,11,21,32,53.c)21,32,53,85
d)32,21,11,10
e)none of the above
(Ans is e)
************************************************************
5)What will be the result of the following segment of the program
main()
{
char *s="hello world";
int i=7;
printf("%.*%s",s);
}
a)syntax error
b)hello w
c)
d)
e)
(Ans is b)
************************************************************
6) What will be the result of the following program
main()
{
int a,b;
printf("enter two numbers :");
scanf("%d%d",a,b);
printf("%d+%d=%d",a,b,a+b);
}
a)- - - - -
b) - --
c) will generate run time error /core dump
d)
e)
(Ans is c)
************************************************************
7) What is the size of 'q'in the following program?
union{
int x;
char y;
struct {
char x;
char y;
int xy;}p;.}q;
a)11
b)6
c)4
d)5
e)none
(Ans is b why because no of bytes for int =4 given in instructions)
************************************************************
8)What will be the result of the following program
main()
{
char *x="String";
char y[] = "add";
char *z;
z=(char *) malloc(sizeof(x)+sizeof(y)=1);
strcpy(z,y);
strcat(z,y);
printf("%s+%s=%s",y,x,z);
}
a)Add+string=Add string
b)syntax error during compilation
c)run time error/core dump
d)add+string=
e)none
(Ans will be e consider cap&small leters)
************************************************************
9) Result 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
(Ans is d)
************************************************************
10) What is the result
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
(Ans is c)
************************************************************
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////
IBM
1. What will be the result of the following program?
main()
{char p[]="String";
int x=0;
if(p=="String")
{printf("Pass 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");.}
else
{
printf("Fail 1");
if(p[sizeof(p)-2]=='g')
printf("Pass 2");
else
printf("Fail 2");
}
}
a) Pass 1, Pass 2
b) Fail 1, Fail 2
c) Pass 1, Fail 2
d) Fail 1, Pass 2
e) syntax error during compilation
************************************************************
2. Which of the choices is true for the mentioned declaration ?
const char *p;
and
char * const p;
a) You can't change the character in both
b) First : You can't change the characterr & Second : You can;t change the pointer
c) You can't change the pointer in both
d) First : You can't change the pointer & Second : You can't chanage the character
e) None
************************************************************
3. The redirection operators > and >>
a) do the same function
b) differ : > overwrites, while >> appends
c) differ : > is used for input while >> is used for output
d) differ : > write to any file while >> write only to standard output
e) None of these
Ans. (b)
************************************************************
4.enum number { a=-1, b= 4,c,d,e}
What is the value of e ?
(a) 7
(b) 4
(c) 5
(d) 15
(e) 3
************************************************************
5.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
Ans. (d)
************************************************************
6. 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
Ans. (c)
************************************************************.7.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
Ans. (b)
************************************************************
8. 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
Ans. (a)
************************************************************
9.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
Ans. (b)
************************************************************
10. What will be result of the following program?
void myalloc(char *x, int n)
{x= (char *)malloc(n*sizeof(char));
memset(x,\0,n*sizeof(char));
}
main()
{char *g="String";
myalloc(g,20);
strcpy(g,"Oldstring");
printf("The string is %s",g);
}
a) The string is : String
b) Run time error/Core dump
c) The string is : Oldstring
d) Syntax error during compilation
e) None of these
************************************************************
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
TCS - C TEST
1. The C language terminator is
(a) semicolon
(b) colon
(c) period
(d) exclamation mark
************************************************************
2. What is false about the following -- A compound statement is
(a) A set of simple statments
(b) Demarcated on either side by curly brackets.(c) Can be used in place of simple
statement
(d) A C function is not a compound statement.
************************************************************
3. What is true about the following C Functions
(a) Need not return any value
(b) Should always return an integer
(c) Should always return a float
(d) Should always return more than one value
************************************************************
4. Main must be written as
(a) The first function in the program
(b) Second function in the program
(c) Last function in the program
(d) Any where in the program
************************************************************
5. Which of the following about automatic variables within a function is correct ?
(a) Its type must be declared before using the variable
(b) Tthey are local
(c) They are not initialised to zero
(d) They are global
************************************************************
6. Write one statement equivalent to the following two statements
x=sqr(a);
return(x);
Choose from one of the alternatives
(a) return(sqr(a));
(b) printf("sqr(a)");
(c) return(a*a*a);
(d) printf("%d",sqr(a));
************************************************************
7. Which of the following about the C comments is incorrect ?
(a) Ccommentscan go over multiple lines
(b) Comments can start any where in the line
(c) A line can contain comments with out any language statements
(d) Comments can occur within comments
************************************************************
8. What is the value of y in the following code?
x=7;
y=0;.if(x=6) y=7;
else y=1;
(a) 7
(b) 0
(c) 1
(d) 6
************************************************************
9. Read the function conv() given below
conv(int t){
int u;
u=5/9 * (t-32);
return(u);
}
What is returned
(a) 15
(b) 0
(c) 16.1
(d) 29
************************************************************
10. Which of the following represents true statement either x is in the range of 10
and 50
or y is zero
(a) x >= 10 && x <= 50 || y = = 0
(b) x<50
(c) y!=10 && x>=50
(d) None of these
************************************************************
11. Which of the following is not an infinite loop ?
(a) while(1)\{ ....}
(b) for(;;)
{
...
}
(c) x=0;
do{
/*x unaltered within the loop*/
.....}
while(x = = 0);
(d) # define TRUE 0
...
while(TRUE){
....}
************************************************************.12. What does the
following function print?
func(int i)
{ if(i%2)return 0;
else return 1;}
main()
{
int =3;
i=func(i);
i=func(i);
printf("%d",i);
}
(a) 3
(b) 1
(c) 0
(d) 2
************************************************************
13. How does the C compiler interpret the following two statements
p=p+x;
q=q+y;
(a) p=p+x;
q=q+y
(b)p=p+xq=q+y
(c)p=p+xq;
q=q+y
(d)p=p+x/q=q+y
************************************************************
For questions 14,15,16,17 use the following alternatives
a.int
b.char
c.string
d.float
14. '9'
************************************************************
15. "1 e 02"
************************************************************
16. 10e05
************************************************************
17. 15
************************************************************
18. Read the folllowing code
# define MAX 100
# define MIN 100
.........
if(x>MAX)
x=1;
else if(x<MIN)
x=-1;
x=50;
if the initial value of x=200,what is the value after executing this code?
(a) 200
(b) 1
(c) -1
(d) 50
************************************************************
19. A memory of 20 bytes is allocated to a string declared as char *s
then the following two statements are executed:
s="Entrance"
l=strlen(s);
what is the value of l ?
(a)20
(b)8
(c)9
(d)21
************************************************************
20. Given the piece of code
int a[50];
int *pa;
pa=a;
To access the 6th element of the array which of the following is incorrect?
(a) *(a+5)
(b) a[5]
(c) pa[5]
(d) *(*pa + 5}
************************************************************
21. Consider the following structure:
struct num nam{
int no;
char name[25];
}
struct num nam n1[]={{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}};
.....
.....
printf("%d%d",n1[2],no,(*(n1 + 2),no) + 1);
What does the above statement print?.(a) 8,9
(b) 9,9
(c) 8,8
(d) 8,unpredictable value
************************************************************
22. Identify the in correct expression
(a) a=b=3=4;
(b) a=b=c=d=0;
(c)float a=int b=3.5;
(d)int a; float b; a=b=3.5;
************************************************************
23. Regarding the scope of the varibles;identify the incorrect statement:
(a)automatic variables are automatically initialised to 0
(b)static variables are are automatically initialised to 0
(c)the address of a register variable is not accessiable
(d)static variables cannot be initialised with any expression
************************************************************
24. cond 1?cond 2?cond 3?:exp 1:exp 2:exp 3:exp 4;
is equivalent to which of the following?
(a)if cond 1
exp 1;
else if cond 2
exp 2;
else if cond 3
exp 3;
else exp 4;
(b) if cond 1
if cond 2
if cond 3
exp 1;
else exp 2;
else exp 3;
else exp 4;
(c) if cond 1 && cond 2 && cond 3
exp 1 |exp 2|exp 3|exp 4;
(d) if cond 3
exp 1;
else if cond 2 exp 2;
else if cond 3 exp 3;
else exp 4;
************************************************************
25. The operator for exponencation is.(a) **
(b) ^
(c) %
(d) not available
************************************************************
26. Which of the following is invalid
(a) a+=b
(b) a*=b
(c) a>>=b
(d) a**=b
************************************************************
27. What is y value of the code if input x=10
y=5;
if (x==10)
else if(x==9)
else y=8;
(a)9
(b)8
(c)6
(d)7
************************************************************
28. What does the following code do?
fn(int n,int p,int r){
static int a=p;
switch(n){
case 4:a+=a*r;
case 3:a+=a*r;
case 2:a+=a*r;
case 1:a+=a*r;}}
(a)computes simple interest for one year
(b)computes amount on compound interest for 1 to 4 years
(c)computes simple interest for four year
(d)computes compound interst for 1 year
************************************************************
29. a=0;
while(a<5)
printf("%d\\n",a++);
How many times does the loop occurs?
(a)infinite
(b)5
(c)4
(d)6
************************************************************
30. How many times does the loop iterated ?.for (i=0;i=10;i+=2)
printf("Hi\\n");
(a)10
(b) 2
(c) 5
(d) None of these
************************************************************
31. What is incorrect among the following
A recursive function
(a) calls itself
(b) is equivalent to a loop
(c) has a termination condition
(d) does not have a return value at all
************************************************************
32. Which of the following go out of the loop if expn 2 becoming false
(a) while(expn 1)\{...if(expn 2)continue;}
(b) while(!expn 1)\{if(expn 2)continue;...}
(c) do{..if(expn 1)continue;..}while(expn 2);
(d) while(!expn 2)\{if(expn 1)continue;..\}
************************************************************
33. Consider the following program
main()
{unsigned int i=10;
while(i>=0){
printf("%u",i)
i--;}
}
How many times the loop will get executed
(a)10
(b)9
(c)11
(d)infinite
************************************************************
34.Pick out the add one out
(a) malloc()
(b) calloc()
(c) free()
(d) realloc()
************************************************************
35.Consider the following program
main(){
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];.}
The value of b[-1] is
(a) 1
(b) 3
(c) -6
(d) none
************************************************************
36. # define prod(a,b)=a*b
main(){
int x=2;
int y=3;
printf("%d",prod(x+2,y-10)); }
the output of the program is
(a) 8
(b) 6
(c) 7
(d) None
************************************************************
37.Consider the following program segment
int n,sum=1;
switch(n){
case 2:sum=sum+2;
case 3:sum*=2;
break;
default:sum=0;}
If n=2, what is the value of sum
(a) 0
(b) 6
(c) 3
(d) None of these
************************************************************
38. Identify the incorrect one
1.if(c=1)
2.if(c!=3)
3.if(a<b)then
4.if(c==1)
(a) 1 only
(b) 1&3
(c) 3 only
(d) All of the above
************************************************************
39. The format specified for hexa decimal is
(a) %d
(b) %o.(c) %x
(d) %u
************************************************************
40. Find the output of the following program
main(){
int x=5, *p;
p=&x
printf("%d",++*p);
}
(a) 5
(b) 6
(c) 0
(d) none of these
************************************************************
41.Consider the following C code
main(){
int i=3,x;
while(i>0){
x=func(i);
i--; }
int func(int n){
static sum=0;
sum=sum+n;
return(sum);}
The final value of x is
(a) 6
(b) 8
(c) 1
(d) 3
************************************************************
42. Int *a[5] refers to
(a) array of pointers
(b) pointer to an array
(c) pointerto a pointer
(d) none of these
************************************************************
43.Which of the following statements is incorrect
(a) typedef struct new{
int n1;
char n2;
} DATA;.(b) typedef struct {
int n3;
char *n4;}ICE;
(c) typedef union{ int n5;
float n6;} UDT;
(d) #typedef union {
int n7;
float n8;} TUDAT;
************************************************************
44.What is the output of the following program
main ()
{
unsigned int i;
for (i = 10; i >= 0; i--)
printf ("%d", i);
}
a) prints numbers 10 - 0 b) prints nos 10 - 1
c) d) goes into infinite loop
************************************************************
45. What is the value of the following expression?
i = 1;
i << 1 % 2
a) 2 b)
c) 1 d) 0
************************************************************
46. What is the value of the following expression?
i = 1;
i = (i <<= 1 % 2)
a) 2 b)
c) 0 d) erroneous syntax
What is the result?
************************************************************
47) *A + 1 - *A + 3
a) - b) -2
c) 4 d) none of the above
************************************************************
48) &A[5] - &A[1]?
a) b)
c) 4 d).************************************************************
49) C allows
a) only call by value
b) only call by reference
c) both
d) only call by value and sometimes call by reference
************************************************************
50) The following statement is
" The size of a struct is always equal to the sum
of the sizes of its members"
a) valid b) invalid c) can't say
************************************************************
51) How many x's are printed?
for (i = 0, j = 10; i < j; i++, j--)
printf ("x");
a) 10 b) 5 c) 4 d) none
************************************************************
52) output?
main ()
{
int i = 2, j = 3, k = 1;
swap (i, j)
printf ("%d %d", i, j);
}
swap (int i, int j)
{
int temp;
temp = i; i = j; j = temp;
}
YOU KNOW THE ANSWER
************************************************************
53) main ()
{
int i = 2;
twice (2);
printf ("%d", i);
}
twice (int i)
{
bullshit.}
int i, b[] = {1, 2, 3, 4, 5}, *p;
p = b;
++*p;
p += 2;
************************************************************
54) What is the value of *p;
a) 2 b) 3 c) 4 d) 5
************************************************************
55) What is the value of (p - (&p - 2))?
a) b) 2 c) d)
************************************************************
56) x = fopen (b, c)
what is b?
a) pointer to a character array which contains the filename
b) filename whithin double quotes
c) can be anyone of the above
d) none
************************************************************
57) x = malloc (y). Which of the following statements is correct.
a) x is the size of the memory allocated
b) y points to the memory allocated
c) x points to the memory allocated
d) none of the above
************************************************************
58) which is the valid declaration?
a) #typedef struct { int i;}in;
b) typedef struct in {int i;};
c) #typedef struct int {int i;};
d) typedef struct {int i;} in;
************************************************************
59) union {
int no;
char ch;
} u;
What is the output?
u.ch = '2';
u.no = 0;.printf ("%d", u.ch);
a) 2 b) 0 c) null character d) none
************************************************************
60) Which of these are valid declarations?
i) union { ii) union u_tag {
int i; int i;
int j; int j;
}; };
iii) union { iv) union {
int i; int i;
int j; int j;
FILE k; }u;
};
a) all correct b) i, ii, iv
c) ii & iv d)
************************************************************
61) p and q are pointers to the same type of dataitems.
Which of these are valid?
i) *(p+q)
ii) *(p-q)
iii) *p - *q
a) all
b)
c) iii is valid sometimes
************************************************************
62) which are valid?
i) pointers can be added
ii) pointers can be subtracted
iii) integers can be added to pointers
a) all correct b) only i and ii
************************************************************
63) int *i;
float *f;
char *c;
which are the valid castings?
i) (int *) &c
ii) (float *) &c
iii) (char *) &i.************************************************************
64) int i = 20;
printf ("%x", i);
what is the output?
a) x14 b) 14 c) 20 d) none of the above
************************************************************
65) main ()
{
char *name = "name";
change (name);
printf ("%s", name);
}
change (char *name)
{
char *nm = "newname";
name = nm;
}
what is the output?
a) name b) newname c) name = nm not valid
d) function call invalid
************************************************************
66) char name[] = {'n', 'a', 'm', 'e'}
printf ("name = \n%s", name);
a) name =
name
b) name =
followed by funk characters
c) name = \nname
d) none
************************************************************
67) int a = 0, b = 2;
if (a = 0)
b = 0;
else
b *= 10;
what is the value of b?
a) 0 b) 20 c) 2 d) none
************************************************************
68) int x = 2, y = 2, z = 1;
what is the value of x afterh the following statmements?.if (x = y%2)
z = crap
else
crap
a) 0 b) 2 c)1 d)none
************************************************************
69) output?
initially n = -24;
printd (int n)
{
if (n < 0)
{
printf ("-");
n = -n;
}
if (n % 10)
printf ("%d", n);
else
printf ("%d", n/10);
printf ("%d", n);
}
a. -24 b.24 c. d.-224
************************************************************
70) float x, y, z;
scanf ("%f %f", &x, &y);
if input stream contains "4.2 3 2.3 ..." what will x and y contain
after scanf?
a. 4.2, 3.0
b. 4.2, 2.3
c.
d.
************************************************************
71) #define max(a,b) (a>b?b:a)
#define squre(x) x*x
int i = 2, j = 3, k = 1;
printf ("%d %d", max(i,j), squre(k));
output?.a.32 b.23 c.31 d.13
************************************************************
72) struct adr {
char *name;
char *city;
int zip;
};
struct adr *adradr;
which are valid references?
i) adr->name X
ii) adradr->name
iii) adr.zip X
iv) adradr.zip
************************************************************
73) main (x, y)
int x, char *y[];
{
printf ("%d %s", x, y[1]);
}
output when invoked as
prog arg1
a. 1 prog b. 1 arg1 c. 2 prog d. 2 arg1
************************************************************
75) extern int s;
int t;
static int u;
main ()
{
}
which of s, t and u are availeble to a function present in another
file
a. only s
b. s & t
c. s, t, u
d. none
************************************************************
76) main ()
{
}.int a;
f1(){}
f2(){}
which of the functions is int a available for?
a. all of them
b. only f2
c. only f1
d. f1 and f2 only
************************************************************
int a = 'a', d = 'd';
char b = "b", c = "cr";
main ()
{
mixup (a, b, &c);
}
mixup (int p1, char *p2, char **p3)
{
int *temp;
....doesnt matter.....
}
77) what is the value of a after mixup?
a. a b.b c.c d.none of the above
````````````````````````````````````````````````
78) what is the value of b after mixup?
a. a b.b c.c d.none of the above
************************************************************
79) main ()
{
char s[] = "T.C.S", *A;
print(s);
}
print (char *p)
{
while (*p != '\0')
{
if (*p != ".")
printf ("%s", *p);
p++;.}
}
output?
a.T.C.S
b.TCS
c.
d. none of the above
************************************************************
80) main ()
{
int ones, twos, threes, others;
int c;
ones = twos = threes = others = 0;
while ((c = getchar ()) != EOF)
{
switch (c)
{
case '1': ++ones;
case '2': ++twos;
case '3': ++threes;
break;
default: ++others;
break;
}
}
printf ("%d %d", ones, others);
}
if the input is "1a1b1c" what is the output?
a. 13
b.
c. 33
d. 31
*********************************************************
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
ECE TNP Test
1. what is the o/p of the following 'C' program
#include<stdio.h>
int main(unsigned val).{
if(val>10) return 1;
printf("\nThe program has run for %d time ",val);
main(val++);
}
a)infinitely runs b)prints the quote 10 times c)prints the quote 9 times d)shows a
syntax
error e)system hangs after sometime due to stack overflow.
************************************************************
2. write the o/p of the following program
#include<stdio.h>
int main()
{
printf("\n\the person is rama");
}
************************************************************
3. predict the o/p of the following program
#include<stdio.h>
main()
{
unsigned u=400;
u*=400/400;
printf("%u",u);
}
a)400 b)84 c)72 d)out of range error
e)none of the above.
************************************************************
4. In the declaration
char **p;
which of the following are true?
I) p is a pointer
II) *p is a pointer
III) should allocate memory for *p and p separately for using this type of
variable.
IV)p is equivalent to a two dimensional array like
char p[10][10];
a)I ,II &III b)I,II,III & IV c)I,IV d)I only e)I and II only
************************************************************
5. The following declaration in 'C'.char c[012];
results in
a)allocation of 12 bytes of memory to char c
b)allocation of 10 bytes of memory to char c
c)syntax error.
d)doesn't allocate any memory
************************************************************
6. A 'C' program evaluates an expression
a)from L-R b) R-L c)either way context dependent
d)None of the above
************************************************************
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////
RAMCO C'QUESTION PAPER
************************************************************
1).
--------------------------------------------------------------
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
Ans : An empty String
************************************************************
2).
--------------------------------------------------------------
main()
{
int x=20,y=35;
x = y++ + x++;
y = ++y + ++x;
printf("%d %d\n",x,y);
}.Ans 57 94
************************************************************
3).
--------------------------------------------------------------
main()
{
int x=5;
printf("%d %d %d\n",x,x<<2,x>>2);
}
Ans 5 20 1
************************************************************
4).
---------------------------------------------------------------
#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;
}
Ans 10 5
10 5
************************************************************
5).
--------------------------------------------------------------
main()
{.char *ptr = "Ramco Systems";
(*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s\n",ptr);
}
Ans Samco Systems
amco Systems
************************************************************
6).
--------------------------------------------------------------
#include<stdio.h>
main()
{
char s1[]="Ramco";
char s2[]="Systems";
s1=s2;
printf("%s",s1);
}
Ans Compilation error giving it cannot be an modifible 'lvalue'
************************************************************
7).
--------------------------------------------------------------
#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);
}
Ans : RamcoSystems
************************************************************.8).
--------------------------------------------------------------
int x;
main()
{
int x=0;
{
int x=10;
x++;
change_value(x);
x++;
Modify_value();
printf("First output: %d\n",x);
}
x++;
change_value(x);
printf("Second Output : %d\n",x);
Modify_value();
printf("Third Output : %d\n",x);
}
Modify_value()
{
return (x+=10);
}
change_value()
{
return(x+=1);
}
Ans : 12 1 1
************************************************************
9).
--------------------------------------------------------------
main()
{
int x=10,y=15;
x=x++;
y=++y;
printf("%d %d\n",x,y);
}.Ans : 11 16
************************************************************
10).
--------------------------------------------------------------
main()
{
int a=0;
if(a=0) printf("Ramco Systems\n");
printf("Ramco Systems\n");
}
Ans : Ony one time
"Ramco Systems"
will be printed
************************************************************
11)
#include<stdio.h>
int SumElement(int *,int);
void main(void)
{
int x[10];
int i=10;
for(;i;)
{
i--;
*(x+i)=i;
}
printf("%d",SumElement(x,10));
}
int SumElement(int array[],int size)
{
int i=0;
float sum=0;
for(;i<size;i++)
sum+=array[i];
return sum;
}
************************************************************
12).#include<stdio.h>
void main(void);
int printf(const char*,...);
void main(void)
{
int i=100,j=10,k=20;
int sum;
float ave;
char myformat[]="ave=%.2f";
sum=i+j+k;
ave=sum/3.0;
printf(myformat,ave);
}
************************************************************
13)
#include<stdio.h>
void main(void);
void main(void)
{
int a[10];
printf("%d",((a+9) + (a+1)));
}
************************************************************
14)
#include<stdio.h>
void main(void);
void main(void)
{
struct s{
int x;
float y;
}s1={25,45.00};
union u{
int x;
float y;
} u1;
u1=(union u)s1;
printf("%d and %f",u1.x,u1.y);
}
************************************************************
15).#include<stdio.h>
void main(void)
{
unsigned int c;
unsigned x=0x3;
scanf("%u",&c);
switch(c&x)
{
case 3: printf("Hello!\t");
case 2: printf("Welcome\t");
case 1: printf("To All\t");
default:printf("\n");
}
}
************************************************************
16)
#include<stdio.h>
int fn(void);
void print(int,int(*)());
int i=10;
void main(void)
{
int i=20;
print(i,fn);
}
void print(int i,int (*fn1)())
{
printf("%d\n",(*fn1)());
}
int fn(void)
{
return(i-=5);
}
************************************************************
17)
#include<stdio.h>
void main(void);
void main(void)
{
char numbers[5][6]={"Zero","One","Two","Three","Four"};
printf("%s is %c",&numbers[4][0],numbers[0][0]);
}.int bags[5]={20,5,20,3,20};
void main(void)
{
int pos=5,*next();
*next()=pos;
printf("%d %d %d",pos,*next(),bags[0]);
}
int *next()
{
int i;
for(i=0;i<5;i++)
if (bags[i]==20)
return(bags+i);
printf("Error!");
exit(0);
}
************************************************************
18)
#include<stdio.h>
void main(void)
{
int y,z;
int x=y=z=10;
int f=x;
float ans=0.0;
f *=x*y;
ans=x/3.0+y/3;
printf("%d %.2f",f,ans);
}
************************************************************
19)
#include<stdio.h>
void main(void);
double dbl=20.4530,d=4.5710,dblvar3;
void main(void)
{
double dbln(void);
dblvar3=dbln();
printf("%.2f\t%.2f\t%.2f\n",dbl,d,dblvar3);
}.double dbln(void)
{
double dblvar3;
dbl=dblvar3=4.5;
return(dbl+d+dblvar3);
}
************************************************************
20)
#include<stdio.h>
static int i=5;
void main(void)
{
int sum=0;
do
{
sum+=(1/i);
}while(0<i--);
}
************************************************************
21)
#include<stdio.h>
void main(void)
{
int oldvar=25,newvar=-25;
int swap(int,int);
swap(oldvar,newvar);
printf("Numbers are %d\t%d",newvar,oldvar);
}
int swap(int oldval,int newval)
{
int tempval=oldval;
oldval=newval;
newval=tempval;
}
************************************************************
22)
#include<stdio.h>
void main(void);
void main(void)
{
int i=100,j=20;.i++=j;
i*=j;
printf("%d\t%d\n",i,j);
}
************************************************************
23)
#include<stdio.h>
void main(void);
int newval(int);
void main(void)
{
int ia[]={12,24,45,0};
int i;
int sum=0;
for(i=0;ia[i];i++)
{
sum+=newval(ia[i]);
}
printf("Sum= %d",sum);
}
int newval(int x)
{
static int div=1;
return(x/div++);
}
************************************************************
24)
#include<stdio.h>
void main(void);
void main(void)
{
int var1,var2,var3,minmax;
var1=5;
var2=5;
var3=6;
minmax=(var1>var2)?(var1>var3)?var1:var3:(var2>var3)?var2:var3;
printf("%d\n",minmax);
}
************************************************************
25)
#include<stdio.h>.void main(void);
void main(void)
{
void pa(int *a,int n);
int arr[5]={5,4,3,2,1};
pa(arr,5);
}
void pa(int *a,int n)
{
int i;
for(i=0;i<n;i++)
printf("%d\n",*(a++)+i);
}
************************************************************
26)
#include<stdio.h>
void main(void);
void print(void);
void main(void)
{
print();
}
void f1(void)
{
printf("\nf1():");
}
#include "6.c"
void print(void)
{
extern void f1(void);
f1();
}
static void f1(void)
{
printf("\n static f1().");
}
************************************************************
27)
#include<stdio.h>
void main(void);
static int i=50;.int print(int i);
void main(void)
{
static int i=100;
while(print(i))
{
printf("%d\n",i);
i--;
}
}
int print(int x)
{
static int i=2;
return(i--);
}
************************************************************
28)
#include<stdio.h>
void main(void);
typedef struct NType
{
int i;
char c;
long x;
} NewType;
void main(void)
{
NewType *c;
c=(NewType *)malloc(sizeof(NewType));
c->i=100;
c->c='C';
(*c).x=100L;
printf("(%d,%c,%4Ld)",c->i,c->c,c->x);
}
************************************************************
29)
#include<stdio.h>
void main(void);
const int k=100;
void main(void)
{
int a[100];
int sum=0;.for(k=0;k<100;k++)
*(a+k)=k;
sum+=a[--k];
printf("%d",sum);
}
************************************************************
///
MASCOT 'C' QUESTIONS
************************************************************
1. Struct(s)
{
int a;
long b;
}
Union (u)
{int a;
long b;
}
Print sizeof(s)and sizeof(u) if sizeof(int)=4 and sizeof(long)=4
************************************************************
2.Switch (i)
i=1;
case 1
i++;
case 2
++i;
break; ( ans : 1,2,3,none)
case 3
--i;
Output of i after executing the program
************************************************************
3. char S;
char S[6]= " HELLO";
printf("%s ",S[6]);
output of the above program ? (0, ASCII 0, I, unpredictable)
************************************************************
4. Unsigned char c;
for ( c=0;c!=256;c++2).printf("%d",c);
No. of times the loop is executed ? (127,128,256,infinitely)
************************************************************
5. int i;
i=0;
repeat
i=i+1; <====== PASCAL PROGRAM
print i;
until(i<10)
end
No. of times the loop is executed?
************************************************************
6. Convert (int A,var ,int B;int c)
{
A=10;
B=4-;
C=120;
}
Convert (inta,b,c)
{ <====== PASCAL PROGRAM
a=1;
b=4;
c=12;
}
convert (A,B,c) ? (10,40,120
10,40,12,..........,............)
************************************************************
7. Procedure A
Begin
--------
end <====== PASCAL PROGRAM
Procedure B No. Of errors in the program ?(1,2,3,none)
Begin
-----------
end
************************************************************.8. int i;
i=2;
i++;
if(i=4)
{
printf(i=4);
}
else
{
printf(i=3);
}
output of the program ? (4,3,unpredictable,none)
************************************************************
//////////////////////////////////////////////////////////////
DBBS 'C' QUESTIONS
************************************************************
1. If i = 5 what is the output of
printf("%d %d %d", ++i ,i ,i++);
a) 5,6,7 b) 6,6,7
c) 7,6,5 (ans) d) 6,5,5
************************************************************
2. For the following code how many times
the printf func. is executed,
Code is :
int i,j;
for (i = 0; i =8 && y >2; (false)
f) a + b; (false)
g) a = b;(true)
h) c+4 ; (true)
************************************************************
3. answer the following in true or false (2 marks)
a) int ctr ; is a valid variable declaration(true)
b) scanf is a keyword(true)
c) stdout is a standard I/P ( false)
d) register variables can be used as loop index for
faster access(false)
e)a = (a>b) is valid statement( true)
f) x = a>b ? x:y is a valid statement( true)
g) given x=1,y=4,z=2 , a=9 and b=3,
evaluate x = x*y/z +a/b ; the value
of x = 5 (ans: true).h) volatile is a keyword (false)
Give one line answers for the following questions:
************************************************************
4.int count = 11; (4 marks)
while (--count+1)
printf("count down is %d \n",count);
how many times the printf statement is executed? ans :11.
************************************************************
5) What is the output generated for the following code. [1 m]
#define square(a) (a*a)
printf("%d",square(4+5));
************************************************************
6. In the following enumeration declaration determine the
value of each member.
eenum compass {north =2 south ,east=1,west
ans: North = 2, south=3, east =1, west =2.
************************************************************
7. for the following declaration
union x{
char ch;
int i;
float j
}u-var;
what is the value of sizeof(u-var)
ans:4.
************************************************************
8. How many bytes of memory will the following arrays need ?
(a) char s[80] ans: 80.
(b) char s[80][10] ans: 800.
(c) int d[10] ans: 20.
(d) float d[10][5] ans: 200.
************************************************************
9. For the follwing statement find the values generated for p and q ?
int p=0,q=1;
p=q++;
p=++q;
p=q--;
p=--q;
The value of p equal to 1 and the value of q equal to
1..************************************************************
10. Write an appropriate declaration for the follwing situations.
x: function returning pointer to array[] of
pointer to function returning char.
Declare a function func that accepts two
integer arguments and returning a pointer to a
long integer.
ans: long int *func(int int)
************************************************************
11. int size ,*int_ptr,table[20];
char ch,*char_ptr;
double d,grid;
Find out the value for the following statements.
a)size=sizeof(int) = 2.
b)size=sizeof(ch) = 1.
c)size=sizeof(size)= 2.
d)size=sizeof(table) =40.
e)size=sizeof(grid) = 160.
f)size=sizeof(char_ptr)= 4.
************************************************************
12. Give the name of the standard library function for the
following
a)string length ans: strlen.
b)string compare ans: strcmp.
c)string copy ans: strcpy.
d)string concatenation ans: strcat.
************************************************************
19.Suppose i and j are both integer type variables, and j has been assigned a value
of
5.Then find the valie of i for the following expressions.
a)i=2*j-2*j/5. ans:8.
b)i=j/2 ans:2.
c)i=2*j/2 ans:4.
d)i=(2*j)/2 ans:5.
************************************************************
20.What is the o/p generated by the following program ?
main()
{
int n=10;
int func(int);
printf("%d",func(n));.}
int func(int n)
{
if(n>0)
return(n+func(n-2));
************************************************************
///////////////////////////////////////////////////////////////////////////////////
/////////////////////////
////////////
SUN C Questions
************************************************************
1.
struct point
{struct point *next;
int data;
}
x;
main()
{int i;
for(x=p;x!=0;)
x=x->next,x++;
freelist(x);
}
freelist(x)
{free(x);
return
}
************************************************************
2.Give the output of the following program
main()
{char *s;
s="hot java";
strcpy(s,"solarrs java")
}
************************************************************

Vous aimerez peut-être aussi