1. What is the output of the program given below

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


2. What is the output of the following program

#include<stdio.h>
   main()
     {
       int i=0;
       fork();
       printf("%d",i++);
       fork();
      printf("%d",i++);
      fork();
      wait();
     }


3. What is the memory allocated by the following definition ?
  int (*x)[10];


4. What is the memory allocated by the following definition ?
int (*x)();


5. In the following program segment

#include<stdio.h>
     main()
    {
      int a=2;
      int b=9;
      int c=1;
     while(b)
  {
     if(odd(b))
     c=c*a;
    a=a*a;
    b=b/2;
  }
printf("%d\n",c);
}

How many times is c=c*a calculated?


6. In the program segment in question 5 what is the value of a at the end of the while loop?


7. What is the output for the program given below

     typedef enum grade{GOOD,BAD,WORST,}BAD;
     main()
    {
        BAD g1;
        g1=1;
        printf("%d",g1);
     }


8. Give the output for the following program.

#define STYLE1 char
      main()
     {
      typedef char STYLE2;
     STYLE1 x;
     STYLE2 y;
     clrscr();
     x=255;
     y=255;
     printf("%d %d\n",x,y);
     }


9. Give the output for the following program segment.

#ifdef TRUE
int I=0;
#endif

main()
{
int j=0;
printf("%d %d\n",i,j);
}


10. In the following program

#include<stdio.h>
main()
{
char *pDestn,*pSource="I Love You Daddy";
pDestn=malloc(strlen(pSource));
strcpy(pDestn,pSource);
printf("%s",pDestn);
free(pDestn);
}

(a)Free() fails
(b)Strcpy() fails
(c)prints I love You Daddy
(d)error


11. What is the output for the following program

     #include<stdio.h>
       main()
      {
      char a[5][5],flag;
      a[0][0]='A';
      flag=((a==*a)&&(*a==a[0]));
      printf("%d\n",flag);
      }

20. Output of the following program is

main()
{int i=0;
for(i=0;i<20;i++)
{switch(i)
case 0:i+=5;
case 1:i+=2;
case 5:i+=5;
default i+=4;
break;}
printf("%d,",i);
}
}

a) 0,5,9,13,17
b) 5,9,13,17
c) 12,17,22
d) 16,21
e) Syntax error

Ans. (d)


24. 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)


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)


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)

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




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



Give the output of the following program

struct XXX
{int a:6;
float b:4;
char s;
}structure;

size of (structure);



main()
{char *s;
s="hot java";
strcpy(s,"solarrs java")
}



main()
{char *p='a';
int *i=100/*p;
}

what will be the value of *i= 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
}



typedef struct
     {char *;
      nodeptr next;
      } * nodeptr ;

      What does nodeptr stand for?

Q2. What does. int *x[](); means ?

Q3. struct list{
       int x;
      struct list *next;
      }*head;

        the struct head.x =100

       Is the above assignment to pointer is correct or wrong ?

Ans. Wrong

Q4.What is the output of the following ?

      int i;
      i=1;
      i=i+2*i++;
      printf(%d,i);

Ans. 4

Q5. FILE *fp1,*fp2;
     
      fp1=fopen("one","w")
      fp2=fopen("one","w")
      fputc('A',fp1)
      fputc('B',fp2)
      fclose(fp1)
      fclose(fp2)
     }

     Find the Error, If Any?

Ans. no error. But It will over writes on same file.

What are the output(s) for the following ?

Q6. #include<malloc.h>
      char *f()
      {char *s=malloc(8);
        strcpy(s,"goodbye");
     }

      main()
      {
      char *f();
      printf("%c",*f()='A');     }

Q7. #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);
      }

Ans. 10 5 0

Q8. 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);

Q9.   #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);
      }

Q10. main()
      {
      printf("hello");
      fork();
      }

Q11. main()
      {
      int i = 10;
      printf(" %d %d %d \n", ++i, i++, ++i);
      }

Q12. #include<stdio.h>
      main()
      {
      int *p, *c,i;
      i = 5;
      p = (int*) (malloc(sizeof(i)));
      printf("\n%d",*p);
      *p = 10;
      printf("\n%d %d",i,*p);
      c = (int*) calloc(2);
      printf("\n%d\n",*c);
      }

Q13. #define MAX(x,y) (x) >(y)?(x):(y)
      main()
      {
      int i=10,j=5,k=0;
      k= MAX(i++,++j);
      printf("%d..%d..%d",i,j,k);
      }

Q14.#include <stdio.h>
      main()
      {
      enum _tag{ left=10, right, front=100, back};
      printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back);
      }

Q15. main()
      {
      int a=10,b=20;
      a>=5?b=100:b=200;
      printf("%d\n",b);
      }

Q16.#define PRINT(int) printf("int = %d ",int)
      main()
      {
      int x,y,z;
      x=03;y=02;z=01;
      PRINT(x^x);
      z<<=3;
      PRINT(x);
      y>>=3;
      PRINT(y);
      }

Q17. #include<stdio.h>
      main()
      {
      char s[] = "Bouquets and Brickbats";
      printf("\n%c, ",*(&s[2]));
      printf("%s, ",s+5);
      printf("\n%s",s);
      printf("\n%c",*(s+2));
      }

Q18. main()
      {
      struct s1
      {
      char *str;
      struct s1 *ptr;
      };
      static struct s1 arr[] = {
                                          {"Hyderabad",arr+1},
                                          {"Bangalore",arr+2},
                                          {"Delhi",arr}
                                       };
      struct s1 *p[3];
      int i;
      for(i=0;i<=2;i++)
      p[i] = arr[i].ptr;
      printf("%s\n",(*p)->str);
      printf("%s\n",(++*p)->str);
      printf("%s\n",((*p)++)->str); }

Q19. .main()
      {
      char *p = "hello world!";
      p[0] = 'H';
      printf("%s",p);
      }



func(int *i, int*j)
{*i=*i * *i;
  *j=*j* *j;
}

main()
{ int i = 5, j = 2;
   func(&i,&j);
   printf("%d %d", i, j);}

What is the output?



void f(char *p)
{p=(char *) malloc(6);
strcpy(p,"hello");
}

void main( )
{char *P="bye";
f(p);
printf("%s',p);
}


For the following C program

int x(char *a)
{a=(char *) malloc(10*sizeof(char));
*a="hello";
}

main()
{char *a="new";
x(a);
printf("%s",a);
}

The output is

a) Hello
b) New
c) Hello new
d) Run time error




void main()
{
int d=5;
printf("%f",d);
}

Ans: Undefined


2.
void main()
{
int i;
for(i=1;i<4,i++)
switch(i)
case 1: printf("%d",i);break;
{
case 2:printf("%d",i);break;
case 3:printf("%d",i);break;
}
switch(i) case 4:printf("%d",i);
}

Ans: 1,2,3,4


3.
void main()
{
char *s="\12345s\n";
printf("%d",sizeof(s));
}

Ans: 6


4.
void main()
{
unsigned i=1; /* unsigned char k= -1 => k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i<j)
printf("less");
else
if(i>j)
printf("greater");
else
if(i==j)
printf("equal");
}

Ans: less


5.
void main()
{
float j;
j=1000*1000;
printf("%f",j);
}

1. 1000000
2. Overflow
3. Error
4. None

Ans: 4


6.  How do you declare an array of N pointers to functions returning
     pointers to functions returning pointers to characters?

Ans: The first part of this question can be answered in at least
        three ways:

    1. char *(*(*a[N])())();

    2. Build the declaration up incrementally, using typedefs:

        typedef char *pc;    /* pointer to char */
        typedef pc fpc();    /* function returning pointer to char */
        typedef fpc *pfpc;    /* pointer to above */
        typedef pfpc fpfpc();    /* function returning... */
        typedef fpfpc *pfpfpc;    /* pointer to... */
        pfpfpc a[N];         /* array of... */

    3. Use the cdecl program, which turns English into C and vice
    versa:

        cdecl> declare a as array of pointer to function returning
            pointer to function returning pointer to char
        char *(*(*a[])())()

    cdecl can also explain complicated declarations, help with
    casts, and indicate which set of parentheses the arguments
    go in (for complicated function definitions, like the one
    above).
    Any good book on C should explain how to read these complicated
    C declarations "inside out" to understand them ("declaration
    mimics use").
    The pointer-to-function declarations in the examples above have
    not included parameter type information. When the parameters
    have complicated types, declarations can *really* get messy.
    (Modern versions of cdecl can help here, too.)


7. A structure pointer is defined of the type time . With 3 fields min,sec hours having pointers to intergers.
    Write the way to initialize the 2nd element to 10.


8. In the above question an array of pointers is declared.
    Write the statement to initialize the 3rd element of the 2 element to 10;


9.
int f()
void main()
{
f(1);
f(1,2);
f(1,2,3);
}
f(int i,int j,int k)
{
printf("%d %d %d",i,j,k);
}

What are the number of syntax errors in the above?

Ans: None.


10.
void main()
{
int i=7;
printf("%d",i++*i++);
}

Ans: 56


11.
#define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");

Ans: "one is defined"


12.
void main()
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=&sum;
*temp=count;
printf("%d %d %d ",count,*temp,sum);
}

Ans: 20 20 20


13. There was question in c working only on unix machine with pattern matching.


14. what is alloca()

Ans : It allocates and frees memory after use/after getting out of scope


15.
main()
{
static i=3;
printf("%d",i--);
return i>0 ? main():0;
}

Ans: 321


16.
char *foo()
{
char result[100]);
strcpy(result,"anything is good");
return(result);
}
void main()
{
char *j;
j=foo()
printf("%s",j);
}

Ans: anything is good.


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

Ans: "harma" (p->add(dharma) && (*p)->harma)
"harma" (after printing, p->add(hewlett-packard) &&(*p)->harma)
"ewlett-packard"



For the following C program

#define AND &&
#define ARRANGE (a>25 AND a<50)
main()
{int a = 30;
if (ARRANGE)
printf("within range");
else
printf("out of range");
}

What is the output?


7. For the following C program

#define AREA(x)(3.14*x*x)
main()
{float r1=6.25,r2=2.5,a;
a=AREA(r1);
printf("\n Area of the circle is %f", a);
a=AREA(r2);
printf("\n Area of the circle is %f", a);
}

What is the output?

Ans. Area of the circle is 122.656250
        Area of the circle is  19.625000


8. What do the following statements indicate. Explain.

    *

      int(*p)[10]
    *

      int*f()
    *

      int(*pf)()
    *

int*p[10]







What is the mistake in the following program segment ?

f()
{
int a;
void c;
f2(&c,&a);}


2. a=0;
    b=(a=0)?2:3;

a) What will be the value of b and why ?
b) If in first statement a=0 is replaced by a = -1,  b= ?
c) If in second statement a=0 is replaced by a = -1, b=?


3. char *a[2];
int const *p;
int *const p;
struct new { int a;int b; *var[5] (struct new)}

Describe the statements in the above given construct ?

4. f()
   {
      int a=2;
      f1(a++);
   }
f1(int c)
{
printf("%d", c);
}

What is the value of c ?

5. 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;
}

What is the value of c?

6. What is the fallacy in the following program segment ?

int *f1()
{
int a=5;
return &a;
}
f()
int *b=f1()
int c=*b;
}

7. Give the C language equivalents of the following
a)Function returning an int pointer
b)Function pointer returning an int pointer
c)Function pointer returning an array of integers
d)Array of function pointer returning an array of integers

8. Find the fallacy in the following program segment?

int a;
short b;
b=a;


9. Define function ? Explain arguments in functions ?


10. How does C pass variables to a function ?

11. Explain the following program segment.
f(){
int *b;
*b=2;
}


12. Explain binary trees and their use ?

13. Draw the diagram showing the function stack, illustrating the variables that 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;
}









1