Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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.
************************************************************
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
************************************************************
2. Are the identifiers name and NAME are same?no
************************************************************
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");
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?
**********************************************************
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
...........................................................
************************************************************
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.
..........................................................
************************************************************
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 "
............................................................
************************************************************
............................................................
************************************************************
ans: (a)
............................................................
************************************************************
............................................................
************************************************************
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};
************************************************************
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);
}
************************************************************
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)=?
************************************************************
12) fact(5)
int n;
fact(n)
{
sum=n*fact(n-1);
}
************************************************************
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;
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;
}
************************************************************
6)fallacy
int a;
short b;
b=a;
************************************************************
HCL Tech.1999-2000
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
************************************************************
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
2)main()
{printf(%d,f(7));
}
f(x)
{if (x<=4)
return(x);
return f(--x);
}
a) 5 b) 4 c) 6 d) 8
************************************************************
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
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??
************************************************************
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)
************************************************************
a. error at runtime
b. compilation error
c.2 3
d. 3 2
************************************************************
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)
************************************************************
11.int x=2;
x=x<<2;
printf("%d ",x);
ANS=8;
************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
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
************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
************************************************************
TCS - C TEST
1. The C language terminator is
(a) semicolon
(b) colon
(c) period
(d) exclamation mark
************************************************************
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
************************************************************
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
************************************************************
47) *A + 1 - *A + 3
a) - b) -2
c) 4 d) none of the above
************************************************************
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
************************************************************
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
}
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
************************************************************
a) all
b)
c) iii is valid sometimes
************************************************************
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
************************************************************
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);
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.
************************************************************
int i = 2, j = 3, k = 1;
printf ("%d %d", max(i,j), squre(k));
output?
a.32 b.23 c.31 d.13
************************************************************
i) adr->name X
ii) adradr->name
iii) adr.zip X
iv) adradr.zip
************************************************************
************************************************************
76) main ()
{
}
int a;
f1(){}
f2(){}
main ()
{
mixup (a, b, &c);
}
mixup (int p1, char *p2, char **p3)
{
int *temp;
....doesnt matter.....
}
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;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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
************************************************************
************************************************************
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
************************************************************
1).
--------------------------------------------------------------
main()
{
char *p1="Name";
char *p2;
p2=(char *)malloc(20);
while(*p2++=*p1++);
printf("%s\n",p2);
}
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);
}
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);
}
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");
}
************************************************************
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);
}
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);
}
************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
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]);
4. Unsigned char c;
for ( c=0;c!=256;c++2)
printf("%d",c);
5. int i;
i=0;
repeat
i=i+1; <====== PASCAL PROGRAM
print i;
until(i<10)
end
No. of times the loop is executed?
************************************************************
7. Procedure A
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)
************************************************************
//////////////////////////////////////////////////////////////
************************************************************
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
************************************************************
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.
************************************************************
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.
************************************************************
************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////
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")
}
************************************************************