Search here

Custom Search

5/28/2012

Part 2: FRP Dumps | C Puzzle | C++ Puzzle | DataStructure Puzzle


PART 1          PART 2          PART 3           PART 4            PART 5            PART 6            PART 7


 Part 2:-
  
47)       void main()
            {
              int *j,*k;
               int a=5,b=8;
              j=&a;
              k=&b;
              j=j*2;
               k=j/2;
               printf("%d %d",*j,*k);
            }         


48)       To make a pointer 'cursor'as a tail node,which line is correct
                        a) cursor->right==NULL
                        b) cursor->left==NULL
                        c) cursor==NULL
                        d) cursor->left==0


49)       Single linked list has a lnk to the next address
                        a) true
                        b) false


50)       int 5[x]={1,2,3,4,5};
            printf("%d",2[x]);


51)       int arr[]={1,2,3,4,5};
            printf("%d %d",arr,&arr);


52)       int a[3][4]={1,2,3,4,5,6,7,8,9,0};
            printf("%d %d",a,a[2][1]);

53)       The argc,argv are initialised in
                        a) header file
                        b) within main
                        c) outside main
                        d) none


54)       Queue is
                        i) First in first out
                        ii) used in expression evaluation.
            a) i only
            b) ii only
            c) both i and ii
            d) neither i nor ii

55)       which is correct?
            a) Auto variables are local variables
            b) Extern variables are global variables
            c) static variables are global variables
            d) registers are local variables

56)       main()
            {
              int i=5;
              int *p;
              p=&5;
              printf("%d %d",i,*p);
            }         


57)       int foo(int a,float b)
            {
               float c;
               c=(float)a+b;
            printf("%c",c);
            }
            main()
            {
              ?????
              foo(8,12.5);
            }
            which line is replaced for ?????? to get the ouput of 20.5


58)       main()
            {
               float v;
               v=10/4.0;
              printf("%f",v);
            }



59)       In a doubly linked list, p1 and p2 are the 2 nodes and node nd is inserted as
               nd->next=NULL
               nd->prev=p1->next



60)     void main()
            {
              int i=12,j,*p;
               p=&i;
              j=++*p+8;
             printf("%d",j);
            }



1.      What is the output of the following:
unsigned  i=32768;
void main()
{
                             printf("%d",i);
   }

a.       32768              b.   -32768        c.   Error        d.   None of the above
Ans::b

2.      int i;
void main()
{
                     static int i=3;
                     printf("%d",i);
}

a.       3
b.      Multiple declaration (since I is static)
c.       0
d.      None of the above
Ans::3
3.      What is the output of the following:
main()
{
      void change(char *);
      char *t="test";
      change(t);
      printf("%s",t);

}
void change(char *t)
{
      char *ab="new test";
      *t=*ab;
}
  1. new test       b.   test       c.  nest         d.  None of the above









4.            What would be printed:
#include<stdio.h>
int i=0;
void main()
{
while(i)
{
               switch(i)
               {
                               case 3<2:                printf("Hi");           break;
                               case 3>2:                printf("Hello");      break;
                               default:                  printf("welcome");
               }
               ++i;
}
}
 
a.       Hi          b.  Welcome          c.   No output          d.  Error

Ans::c
# include<stdio.h>
int get();
void main()
{
int x=20;
x=get();
printf("%d ",x);
}
 
int get()
{
return(60);
}
a.       60         b.  Garbage        c.  Error            d.  20
 
5.            swap(int *a,int *b)
{
int *t;
t=a;
a=b;
b=t;
}

void main()
{
int a=10,b=20;
swap(&a,&b);
printf(“%d %d”,a,b);
}

  1. 10 20         b.  20 10        c.  Error        d.  Garbage value
Ans::a

7.
main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0')
++*++p;
printf("%s   %s",p,p1);
}

a.       ibj!gsjfoet             b.  hbj!gsjfoet      c.   hbj!gsjfoet hbj!gsjfoet     d.  None

ans::d

8. main()
{
    char a[100]={“abcdef”};
     a++;
    printf(“%s”,&a[1]);
}

a)       bcdef       b) abcdef        c)compilation error       d) none of the above


9. When fopen() fails to open a file it returns _______
    1. NULL       b.  -1       c.  1       d.  None of the above



10. int i=5;
fun( )
            {
                        printf("%d\n", i * 3);
            }
            main( )
{
int i= 2;
{
                        int i = 3;
                        printf(" %d", i);
                        fun();
}
            }         
a.       3, 15         b.  3, 6            c.   3               d.  0

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

a. 3 2 1 0        b. 3 2 1        c. 2 1 0        d. 2 1

12. P is a character pointer variable then, what will be the output of the following statement.
printf("%d %d",sizeof(p),sizeof(*p));

a. 1   2          b. 2  1           c. 2  2           d. 1  1

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

a. dharma
    harma
    ewlet-packard
b. harma
    hewlet-packard
    siemens
c. harma
    harma
    hewlet-packard
d. harma
   harma
   ewlet-packard




14. void main()
{
char *ptr="Ramco Systems";
 (*ptr)++;
printf("%s\n",ptr);
ptr++;
printf("%s",ptr);
}

a. Samco Systems   Samco Systems            b. Samco Systems   amco Systems
c. amco Systems     amco Systems               d. amco Systems     mco Systems
15.  #include <stdio.h>
    main()
    {
        switch (5)
        {
            case 5: printf(" 5 ");
            default: printf(" 10 ");
            case 6: printf(" 6 ");
        }
    }
  1. 5         B.  5 10 6       C.  5 10       D.  5 6
16. Which of the following is not a storage class in C?
  1. Stack         B. Register        C. Extern         D. Static
17. Which of the following function does not return an integer value?
  1. printf       B. scanf      C. strcpy           D. strlen
18.  int i=5;
int abc(int z)
{
      return i/2;
}
main()
{
       int i=4;
       printf("%d",abc(i=i/4));
}

a)  error          b)  5       c)  2        d)  0

19. What will be the output of the following program :
            int main()
{
 int val=5;
 val=printf("C") + printf("Skills");
             printf("%d",val);
 return(0);
}
(a)    7      (b) C7        (c) Compile-Time Error        (d) CSkills7    



20.  #include<stdio.h>
main()
{
struct xx
{
      int x=3;
      char name[]="hello";
 };
struct xx *s;

printf("%d",s->x);
printf("%s",s->name);
}

  1. 3   hello   b.  Compiler Error    c. Run time error   d. use dot (.) operator
21.  int swap(int *a,int *b)
{
 *a=*a+*b;*b=*a-*b;*a=*a-*b;
}
main()
{
                        int x=10,y=20;
            swap(&x,&y);
                        printf("x= %d y = %d\n",x,y);
}
  1. 20  10        b.  10  20         c. 20  20      d. 10  10

22. main()
{
char *p = “ayqm”;
char c;
c = ++*p++;
printf(“%c”,c);
}
a)       a              b)  b             c)  y            d)  z
23. main()
{
                        float i=1.5;
            switch(i)
                        {
                        case 1: printf("1");
                                    case 1.5: printf("2");
                                    default : printf("0");
            }
}
  1. 0       b.  0  1  2        c. 1  2  0       d. Compiler Error      e. 2  0

24.  If the CPU fails to keep the variables in CPU registers, in that case the variables are assumed
 a) static       b) external        c) global         d) auto
25. The EOF is equivalent to
    1. -1         b.  1      c. 0            d. None of the above

26. In a queue, if rear=max-1, front=0 then what will be the queue
a)  Queue is empty
b)  Queue is full
c)  Queue has only one element
d)  None of the above

27. The postfix expression is ab-cd+*ef/-.The values of a, b, c, d, e,f are
4, 2, 5, 2, 6, 3 respectively. Then the output is

   a)  -6          b)  12          c)  20          d)  None

28. In the stack, if top=0 then the stack is
a)  Stack is empty     b)  Stack is full     c)  Stack has only one element    d)  None

29.  struct node
             {
               int data;
               struct node *left,*right;
            };

nd is a node which is not in the beginning and also not in the end.
How will you remove a node after nd from the list?

a) nd->right=nd->right->left;nd->right->left=nd->left->right;
b) nd->right=nd->right->right;nd->right->left=nd;
c) nd->right=nd->right->left;nd->right->left=nd->right;
d) nd->right=nd->left->right;nd->left->right=nd;

30. In the Given Infix expression which is the root node for your expression tree
(A+B)-(C*D)+G/H*I

a) +            b) -             c) *             d) /


31. Consider the following structure
   struct node
    {
      int info;
      struct node *link;
    };

Suppose ptr is a pointer which is not pointing to the first also not to the last node. Then if you remove a node after ptr from the list, then the code will be

a) ptr=ptr->link;
b) ptr->link=ptr;
c) ptr->link=ptr->link->link;
d) ptr=ptr->link->link;



32. What does below code do, if temp is pointing to a node other than first and last node
           
            temp -> prev ->next = temp ->next;
            temp ->next -> prev = temp -> prev;
            free(temp);

            a)         no effect
            b)         inserts a node
            c)         deletes a node
            d)         shuffling of pointers

33. What is the Infix expression for    - + A / * B C D / * E F G
a)      A + B * C / D – E / F * G
b)      A + B / C * D – E * F / G
c)      A + B * C / D – E * F / G
d)     A - B * C / D + E * F / G

34. What is the postfix expression for A + B * C / D – E * F / G
a)      ABC*D/+EFG*/-
b)      ABC*D/+EF*G/-
c)      ABCD/*+EF*G/-
d)     None of these.

35. A binary tree with 15 nodes have _____ null branches
a)      15         b) 14         c) 16         d) 17

1. union u
       {   
        Int a;
        Char ch[2];
       }u1;
U1.a=5;
U1.ch[0]=4 ;   u1.ch[1]=2;  
Printf(“%d”,a);
}
(a)  5     (b) 42    ( c) 1028   (d)  24  
 
 
36.          Here is an infix expression: 6+2*(1*5-9). Suppose that we are               using the usual stack algorithm to convert the expression from infix to postfix notation. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? 
     a.        1 
     b.       2 
     c.        3 
     d.       4 
e.     5 
 
39.Suppose that p is a pointer variable that contains the NULL   pointer. What happens if your program tries to read or write *p? 
 
    a.         A syntax error always occurs at compilation time. 
    b.        A run-time error always occurs when the program finishes. 
    c.         The results are unpredictable. 
d.        A run-time error always occurs when *p is evaluated
 
 
45.          What kind of list is best to access the item at given position n?" 
    a.         Doubly-linked lists. 
    b.        Lists implemented with an array. 
    c.         Singly-linked lists. 
d.        Doubly-linked or singly-linked lists are equally best 
 
 
50.          Which of the following applications may use a stack? 
    a.         A parentheses balancing program. 
    b.        Evolution of postfix expression. 
    c.         Syntax analyzer for a compiler. 
d.        All of the above. 
 
 
#include<stdio.h>
   void main()
     {
     union a
       {
        int i;
        char ch[2];
        };
     union a u;
     u.ch[0]= 3;
     u.ch[1]= 2;
      printf("%d %d %d",u.ch[0],u.ch[1],u.i);
        }
    a) 3  2  515         b)515  2  3             c) 3  2  5                 d) none of these
 
 
main()
{
struct student 
{
char name[30];
struct date dob;
}stud;
struct date
        {     
         int day,month,year;
         };
     scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month,      &student.dob.year);
}
 
a) It scans perfectly with error             b) scanf format is incorrect   c) No Error d) compilation Error
 
 
In printf(),the appearance of the output of the output can be affected by
 
1) field with                                                        2) conversion character
3) flag                                                                  4) all of the above
 
 
Any of the following programs in c has access to three standard files:
 
1) standard input file, standard output file, standard error file
2) stdin,stdout, stderr
3) keyboard,screen,screen
4) all the above
 
 
Heap
 
1) is a region from where memory is  allocated
2) lies between you program and the stack
3) is a finite area
4) all of the above
 
 
Function definition void check(int i ,char*j) is
1) call by value                                     2)call by reference
3) both (1) and (2)                4)in valid function definition
 
 
Masking is used
 
1)            to copy a portion of a given bit pattern to a new variable,
while the remainder of the new variable is filled with 0’s(using the 
bitwise AND)
2)            to copy a portion of a given bit pattern to a new variable,
while the reminder of the new variable is filled with 1’s (using the bitwise OR) 
3) to copy a portion of a given bit pattern to a new variable, while the remainder of the original bit pattern is inverted within the new variable
4) all of the above
 
 
A fields width specifier in a printf() function
 
1) specifies the maximum value of a number
2) controls the size of type used to print numbers
3) controls the merging of the program listing
4) specifies how many characters positions will be used for a number
 
 
 
The global variables by default belong to 
 
1) the register type                2) the static type
3) the auto type                                    4) the dynamic type
 
 
 
What will be the output of the following program :
               void main()
               {
                 unsigned x=0xf880,y=5,z;
                 z=x<<y;
                 printf("%#x %#x",z,x>>y-1);
               }
(a)1000 f87                           (b)8800 0xf88                                      (c)1000 f88                           (d)0x1000 0xf88
Ans. (d)



int num[26],temp;
            num[0]=100;
            num[25]=200;
            temp=num[25];
            num[25]=num[0];
            num[0]=temp;
            printf("\n%d %d",num[0],num[25]);

            o/p: 200 100

2.         int array[26],i;
            for(i=0;i<=25;i++)
            {
                        array[i]='A'+i;
                        printf("\n%d, %c", array[i],array[i]);
            }
            o/p:65=A to 97-Z

3.         int sub[50],i;
            for(i=0;i<=48;i++)
            {
                        sub[i]=i;
                        printf("\n%d", sub[i]);
            }

o/p:0-48

4.         int a[5]={3,4,5,6,7};
            printf("%d",a);

            o/p: address of a

5.         int i,a[5]={3,4,5,6,7};
            for(i=0;i<5;i++)
            printf("\n%d",a+i);

            o/p: a[i]=a+i
                   adress’s of all int’s is printed

6.         int i,a[5]={3,4,5,6,7};
            printf("\n%d",a[5]);

            o/p: adress of  a[5] is printed

7.         int i,a[5]={3,4,5,6,7};
            for(i=0;i<5;i++)
            printf("\n%d",a[++i]);

            o/p: 4,6,adress value

8.         int i,a[3];
            a[3]=8;
            printf("\n%d",a[3]);

o/p:8

9.         int i,a[2][2]={1,2,3,4};
            for (i=0;i<2;i++)
            printf("%d",a[i][i]);

            o/p: 1,4

10.       int i,a[2][2]={1,2,3,4};
            for (i=0;i<2;i++)
            printf("%d",a[i]);

            o/p: 8230 8234 ( adress’s of int’s)

11.       int i,a[2][2]={1,2,3,4};
            for (i=0;i<2;i++)
            printf("%d , %d\n",a[i]+1);

o/p:8682,8999
                  8686,8999

12.       int a[2][2]={1,2,3,4};
            printf("%d",a);

            o/p: base address of a (1st element) 8686

13.       char a[5][10]={"akshay",
                                    "Parag",
                                    "Chirag",
                                    "Hemal",
                                    "Hetal"};
            printf("%s",a);

            o/p: akshay


14.       char a[5][10]={"akshay",
                                    "Parag",
                                    "Chirag",
                                    "Hemal",
                                    "Hetal"};
            printf("%s",a+2);

            o/p:chirag

15.       char a[5][10]={"akshay",
                                    "Parag",
                                    "Chirag",
                                    "Hemal",
                                    "Hetal"};
            printf("%s",a[+2]);

            o/p:chirag

16.       char a[5][10]={"akshay",
                                    "Parag",
                                    "Chirag",
                                    "Hemal",
                                    "Hetal"};
            printf("%c",a[2]);

o/p:chirag

17.       char a[5][10]={"akshay",
                                    "Parag",
                                    "Chirag",
                                    "Hemal",
                                    "Hetal"};
            printf("%c",a[2][4]);

            o/p:a

18.       char a[5][10]={"akshay",
                                    "Parag",
                                    "Chirag",
                                    "Hemal",
                                    "Hetal"};
            printf("%c",a[2][7]);

            o/p: (some symbol)


19.       char c[2]="A";
            printf("\n%c",c[0]);
            printf("\n%s",c);

            o/p:A
                  A

20.       char s[]="Get organized ! learn C";
            printf("\n%s",&s[2]);
            printf("\n%s",s);
            printf("\n%s",&s);

            o/p: t organized ! learn C
                   Get organized ! learn C";
                   Get organized ! learn C";

21.       char s[]="No two viruses work similarly";
            int i=0;
            while (s[i]!=0)
            {
                        printf("\n%c",s[i]);
                        printf("\n%c",i[s]);
                        i++;
            }

22.       char str1[]={'H','e','l','l','o'};
            char str2[]="Hello";
            printf("\n%s", str1);
            printf("\n%s", str2);

            o/p: Hello garbage values
                   Hello

23.       printf(5+"Good Morning"); o/p: Morning

24.       printf("%c","abcdefgh"[4]);  o/p:e

25.       printf("\n%d%d%d",sizeof('3'),sizeof("3");sizeof(3)); o/p:1 2 2




1.         #include<stdio.h>
            void display();
            void main()
            {
                        printf("\n Only smarties use C?");
                        display();
            }

            void display()
            {
                        printf("\n Brilliants too use C!");
                        main();
            }

            o/p: error cannot call main() from the program

2.         #include<stdio.h>
            void main()
            {
                        printf("\n Only smarties use C?");
                        main();
            }

            o/p: infinite loop

3.         #include<stdio.h>

            int check(int);
            void main()
            {
                        int i=45,c;
                        c=check(i);
                        printf("\n%d",c);
            }

            int check(int ch)
            {
                        if(ch>=45)
                                    return (100);
                        else
                                    return (10);
            }

            o/p:100


4.         #include<stdio.h>
            int check(int);
            void main()
            {
                        int i=45,c;
                        c=check(i *1000);
                        printf("\n%d",c);
            }

            int check(int ch)
            {
                        if(ch>=40000)
                                    return (ch/10);
                        else
                                    return (10);
            }

            o/p:10


5.         int x=10;
            void display();

            void main()
            {
                        int x=20;
                        printf("\n%d",x);
                        display();
            }


            void display()
            {
                        printf("Inside display %d",x);
            }

            o/p: 20,inside display 10



6.         #include<stdio.h>

            int i;
            void increment();
            void decrement();

            void main()
            {
                        printf("\ni=%d",i);
                        increment();
                        increment();
                        decrement();
                        decrement();
            }


            void increment()
            {
                        i=i+1;
                        printf("\non incrementing i=%d",i);
            }

            void decrement()
            {
                        i=i-1;
                        printf("\non decrementing i=%d",i);
            }
            o/p:1 2 1 0

7.         void fun(int,int)
            void main()
            {
                        int i=5,j=2;
                        fun(i,j);
                        printf("\n%d%d",i,j);
            }

            void fun(int i,int j)
            {
                        i=i*i;
                        j=j*j;
            }

            o/p:5,2 (call by value ex:)

8.         void fun(int *,int *);
            void main()
            {
                        int i=5,j=2;
                        fun(&i,&j);
                        printf("\n%d%d",i,j);
            }

            void fun(int *i,int *j)
            {
                        *i=*i * *i;
                        *j=*j * *j;
            }

            o/p: 25 4(call by reference)

9.         void fun(int *x,int y)
            {
                        int i=4,j=2;
                        fun(&i,j);
                        printf("\n%d%d",i,j);
            }

            void fun(int *i,int j)
            {
                        *i=*i * *i;
                        j=j*j;
            }

10.       void fun(void *);
            int i;
            void main()
            {
              void *vptr;
              vptr=&i;
              fun(vptr);
            }

            void fun(void *p)
            {
                        int **q;
                        q=(int **)&p;
                        printf("%d",**q);
            }

            o/p:0

30. float x=1.1;
            while(x==1.1)
            {
                        printf("\n%f",x);
                        x=x-0.1;
            }

o/p: no output

31. int x=3,y=0,z;
            while (x>=0)
            {
                        x--;
                        y++;
                        if(x==y)
                                    continue;
                        else
                                    printf("\n%d%d",x,y);
            }

            o/p: 2 1
                    1 2
                    0 3
                    -1 4

32. int x=4,y=0,z;
            while(x>=0)
            {
                        if(x==y)
                                    break;
                        else
                                    printf("\n%d%d",x,y);
                        x--;
                        y++;
            }

            o/p:4 0
                  3 1

33. int i=0;
            for(i=1;i<=5;printf("\n%d",i));
                        i++;

            o/p: infinite 1’s

34. int i;
            for(;i;)
            printf("\n Here is some mail for you");


35. int i=1, j=1;
            for(;;)
            {
                        if(i>5)
                                    break;
                        else
                                    j+=i;
                        printf("\n%d",j);
                        i+=j;
            }

            o/p:2 5
36. char suite=3;
            switch(suite)
            {
            case 1:
                        printf("\n Diamond");
            case 2:
                        printf("\n Spade");
            default:
                        printf("\n Heart");
            }

o/p:Heart


37. int c=3;
            switch(c)
            {
            case '3':
                        printf("You never win the silver prize");
                        break;
            case 3:
                        printf("You always lose the gold prize");
                        break;
            default:
                        printf("Ofcourse provided you win a prize");
            }

            o/p: You always lose the gold prize


38. int i=3;
            switch(i)
            {
                        case 0:
                                    printf("\nCustomers are dicey");
                        case 1+0:
                                    printf("\nMarkets are pricey");
                        case 4/2:
                                    printf("\nInvestors are moody");
                        case 8%5:
                                    printf("\nAtleast employees are good");
            }

            o/p: Atleast employees are good


39. int k;
    float j=2.0;
            switch(k=j+1)
            {
            case 3:
                        printf("\n Trapped");
                        break;
            default:
                        printf("\n Caught");
            }

            o/p:Trapped


40.int ch='a'+'b';
            switch(ch)
            {
                        case 'a':
                        case 'b':
                                    printf("\nYou entered b");
                        case 'A':
                                    printf("\na as in ashar");
                        case 'b' + 'a':
                                    printf("\n You entered a and b");
            }

            o/p: You entered a and b


41. int i=1;
            switch(i-2)
            {
                        case -1:
                                    printf("\nFeeding Fish");
                        case 0:
                                    printf("\n Weeding grass");
                        case 1:
                                    printf("\n Mending roof");
                        default :
                                    printf("\n Just to survive");
            }


42.       int x=25;
            printf("%d%d%d",x==25,x=50,x<78); o/p:0 50 1
           
43.       int x=25;
            printf("%d%d%d",x==50,x=50,x<78);

44.       int x=50;
            printf("%d%d%d",x<78,x=100,x==50);o/p:0 100 1




1.         int b[]={10,20,30,40,50};
            int i;
            for(i=0;i<=4;i++)
            printf("\n%d",*(b+i));

            o/p: 10,20,30,40,50


2.         int b[]={0,20,0,40,5};
            int i,*k;
            k=b;
            for(i=0;i<=4;i++)
            {
                        printf("\n%d",*k);
                        k++;
            }

            o/p: 0,20,0,40,5


3.         char s[]="No two viruses work similarly";
            int i=0;
            while (s[i]!=0)
            {
                        printf("\n%c",*(s+i));
                        printf("\n%c",*(i+s));
                        i++;
            }


4.         char s[]="Churchgate:no church no gate";
            char t[25];
            char *ss,*tt;
            ss=s;
            while(*ss!='\0')
                        *ss++=*tt++;
            printf("\n%s",t);

            o/p:error


5.         int arr[]={10,20,36,72,45,36};
            int *j,*k;

            j=&arr[4];
            k=(arr +4);

            if(j==k)
                        printf("The two pointers point to the same location");
            else
                        printf("The two pointers do not point to the same location");

            o/p: The two pointers point to the same location


6.         #include<stdio.h>

            void main()
            {
                        int s[2][2]={
                                                {2,2},
                                                {3,3}
                            };

            int i,j;

            for(i=0;i<2;i++)
                        for(j=0;j<2;j++)
                        printf("%d\n",*(*(s+i)+j));
            }

            o/p:2 2 3 3


7.         void main()
            {
                        float a=13.5;
                        float *b,*c;
                        b=&a;
                        c=b;
                        printf("\n%u %u %u",&a,b,c);
                        printf("\n%f %f %f %f %f",a,*(&a),*&a,*b,*c);
            }


8.         int *p,a[3]={1,2,3};
            p=a;
            printf("%d",*p++);
            printf("%d",*a);
            printf("%d",*p);

            o/p:1 1 2


9.         int *p,a;
            a=20;
            p=&a;
            scanf("%d",p);
            printf("A= %d and *P = %d",a,*p);

o/p:20 20


10.       int **q,*p,a,b=40;
            a=20;
            p=&a;
            q=&p;
            *q=&b;
            printf("A= %d and *P = %d and **Q = %d",a,*p,**q);

11.       float *p;
            int a;
            a=30;
            p=&a;
            printf("A= %d and *P=%f",a,*p);

12.       float *p;
            int a;
            a=30;
            p=&a;
            printf("Address of A= %u and Value of P=%u",&a,p);


13.       float a;
            int *p;
            a=30.90;
            p=&a;
            printf("Address of A= %u and Value of P=%u",&a,p);


14.       int a[]={10,20,30,40,50};
            int *p;
            p=a;
            printf("The value of *P is %d\n",*p);
            p++;
            printf("Now the value of *P is %d\n",*p);


15.       int a[]={10,20,30,40,50};
            int *p;
            p=a;
            printf("The value of a[0] is %d\n",*p);
            p++;
            *p=300;
            printf("Now the value of a[1] is %d\n",a[1]);


16.       int a[]={10,20,30,40,50};
            int *p;
            p=a;
            p=p*2;
            printf("%d",*p);


17.       void main()
            {
                        char *str;
                        str="%d\n";
                        printf(str,300);
            }


18.       void main()
            {
                        char *str;
                        str="%d\n";
                        str++;
                        printf(str-1,300);
            }


19.       void main()
            {
                        char *str;
                        str="%4s";
                        printf(str,"K");
            }


20.       void main()
            {
                        int i,*j;
                        i=3;
                        j=&i;
                        printf("%d",i**j*i+*j);
            }

21.       1.         #define disp printf

            void main()
            {
                        disp("Hello World");
            }

           
2.         #define newline "\n"
           
            void main()
            {
                        printf("Hello newline World");
            }


3.         #define pi 3.14

            void main()
            {
                        float d=pi;
                        printf("%f",d);
            }


4.         #define pi 3.14

            void main()
            {
                        float pi=2.11;
                        printf("%f",pi);
            }


5.         #define pi 3.14

            void main()
            {
                        printf("%f",pi);
                        scanf("%f",&pi);
                        printf("%f",pi);
            }


6.         #define maxi(a,b)  a>b?a:b

            void main()
            {
                        float x,y;
                        scanf("%f%f",&x,&y);

                        printf("%f",maxi(x,y));
            }


(1) which of the following lines gives/prints the output 20               

                        void main()
                        {
lint1:                int i=20;
line2:               int *k,**j;
line3:               j=&i;
line4:               k=&j;
line5:               printf("\n%d",i);
line6:               printf("\n%d",**k);
line7:               printf("\n%d",***&k);
                        }

(1) only 5         (2)only 7
(3) only 6         (4)all 5,6,7


ans:(4)



(2)

void main()
{
int x,y=6;
x=y+NULL;
printf("%d",x);
}


o/p:  6


(3)

void main()
{
static int arr[12];
printf("%d",sizeof(arr));
}

o/p: 24



(4)

void main()
{
float a[]={1.2,3.4,5.7,12.3};
int i;
for(i=0;i<=5;++i)
printf("%f   ",a[i]);
}


o/p:  1.200000  3.400000   5.700000   12.300000   0.000000   0.000000



(5)A user-defined function returns a pointer (yes/No)

yes


(6)In a normal c program the library  will be defined in ________________


(7)

void main()
{
printf("%s",7["wipro infortech");
}



(8)

#include<stdio.h>
void main()
{
char *p="hello";
char q[]={'h','e','l','l','o'};
printf("%d  %d",sizeof(*p),sizeof(*q));
}



o/p: 1  1




(9)

#include<stdio.h>
void main()
{
int i=0;
while()
{
    switch(i)
   {
case 3<2:
printf("Hi");
break;
case 3>2:
printf("Hello");
break;
default:
printf("welcome");
    }
    ++i;
}
}

o/p:
error




(10)
void main()
{
int i=0;
while(i<3)
{
switch(i)
{
case 1:
printf("case1");

case 2:
printf("case2");
break;
default:
printf("Default");
}
++i;
}
}

o/p:default case1 case2 case2



(11)
#include<stdio.h>
void main()
{
char str1[]="Hello";
char str2[]="Hello"
if(str1==str2)
printf("\nEqual");
else
printf("\nNot equal");

}

0/p:
Error



(12)
which one of the comment line statement is correct

(1)  /* hello world */
(2)  //hello world//
(3)  */ hello world */
(4)  /&hello world &/

Ans:  (1)



(13)

The value of EOF is _____
(1) NULL                    (2)0
(3)-1                            (4)1


Ans:  (3)

(14)

#include<stdio.h>
void main()
{
int i;
for(i=2;i=0;i--)
{
printf("%d",&i);
}
}


No output


(15)

struct addr
{
char city[5];
char street[5]; 
};
struct emp
{
char name[20];
int empno;
struct addr *a;
};

struct emp *pemp;

How will you access city from the *pemp;
ans: pemp->a->city



(16)

If you want to allocate 2 blocks of memory for a set of 5 integers,which will you use?

(a) malloc                    (b)calloc
(c)neither (a)&(b)        (d)either (a)&(b)


Ans:(d)



(17)

#include<stdio.h>

void main()
{
int i=10;
printf("%d  ",i=50);
}

0/p: 50




(18)

#include<stdio.h>
#define HELLO  hi
void main()
{
printf("HELLO");
}


o/p: HELLO


(19)
Convert to prefix

(a+b)*(c/d)

ans: *+ab/cd



(20)

#include<stdio.h>

struct person
{
char *name;
char *age;
char *c;
};
struct emp
{
int a;
struct person *addr;
};

void main()
{
struct emp *e1;
printf("%d",sizeof(e1));

}


o/p:  4


(21)

#include<stdio.h>
void main()
{
int i;
i=10/4;
printf("%d",i);

}

o/p: 2



(22)

#include<stdio.h>
void main()
{
float i;
i=10/4;
printf("%f",i);

}


o/p: 2.000000



(23)

To arrange nodes in ascending order ________ is used

1)inorder                     2)preorder                   3)postorder                  4)all the above


ans:  inorder



(24)

int i=6,*j;
line1:  j=&i;
line2:  j=&35;
line&:  j=&(i+25);


Which of the above lines are correct?

Ans:  line1




(25)

#include<stdio.h>
void main()
{
int i=10;
printf("%d",i==10);
}

o/p:  1



(26)
#include<stdio.h>
int get();
void main()
{
int x=20;
x=get();
printf("%d ",x);
}

int get()
{
return(60);
}


o/p: 60


(27)

#include<stdio.h>
void main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9};
printf("%d ",a[2][1]);
}


o/p:  0





(28)

#include<stdio.h>
void main()
{
static int a[100];
int i;
for(i=0;i<4;i++)
printf("%d",a[i]);
}


o/p: 0 0 0 0



(29)

which is better memory allocation when size is not known

1)static                        2)dynamic                   3)both              4)neither

ans: dynamic


(30)

struct city
{
char name[10];
char address[0];
};

struct details
{
struct city c;
};
struct details  *d;

How will u access address(member)

1)d->c.address                        2)d.c.address               3)d.c->adddress

Ans:d->c.address



(31)

#include<stdio.h>
void main()
{

int array[]={10,20,30,40,50},*p;
p=&array[0] + 4;  //p=array+4
for(;p>=array;p--)
printf("%d   ",*p);

}

Ans:50  40  30  20 10


(32)

A complete binary tree is
(a)  non-leaf nodes have two child
(b)  all left subtree less than root and root less than right tree
which is correct

1) a alone                     2)b alone         3)neither (a) nor (b)



(33)

Linked list is better than array because of
1) insertion      2)deletion        3)traversal

a) (1) & (2)      b) (2) & (3)


(34)

In the doubly linked list ,to add a new element in the tail node



(35)

#include<stdio.h>
#define wipro main
void wipro()
{

printf("main");

}


o/p:   main


(36)

#include<stdio.h>
#define output(int)  printf("%d ",int)
void main()
{
int a=2,b=3;
output(a);
output(b);
}

o/p:  2  3


(37)

#include<stdio.h>
#define wipro printf
void main()
{

wipro("welcome");

}


o/p: welcome


(38)

Which one of the following statement is false for binary search tree
1) root is less than left and right subtree
2)root is less than left subtree but greater than right


a) 1 only          b) 2 only          c)both 1 and 2             d)neigher 1 nor 2



(39)

#include<stdio.h>
aaa()
{
printf("hi");
}
bbb()
{
printf("hello");
}
ccc()
{
printf("bye");
}
void main()
{
int (*ptr[3])();
ptr[0]=aaa;
ptr[1]=bbb;
ptr[2]=ccc;
ptr[1]();
}


o/p:  hello



(40)
a=15,b=3,c=5,d=3

a*b+c-d
evaluate the expression


Ans:47


(41)

#include<stdio.h>

void main()
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<5;j++)
{
if(i==j)
break;
printf("wipro");
}
}
}

How many times wipro will  be printed

o/p: 1 time



42)

#include<stdio.h>
void main()
{
int a=10,b=10;
a+=1;
printf((a>b)?"hi":"hello");
}

o/p:  hi



43)


which is not an operator in c?
1)&      2)!        3)~       4)::


44)
Which operator is highest  precedence?

a)"=="              b)"*"                c)"+"                d)"->"


45)
#include<stdio.h>
void main()
{
static int a[5];
int i;
for(i=0;i<5;++i)
printf("%d ",a[i]);
}

o/p:  0 0 0 0 0


46)
For allocating 2 blocks of 5 elements of integer type,what we will use?


1)malloc( )   or calloc( )                       2)only malloc
3)calloc( )                                            4)neither malloc( ) nor calloc( )

Ans:  (1)


47)

#include<stdio.h>
struct emp
{
int i;
char name[15];
};

void main()
{
struct emp e1={1,"hi"},*e2;
e2=&e1;
if(e1==e2)
printf("\nstructures are equal");
else
printf("\nstructures are not equal");
}


Ans:

error


48)
The arguments in a function call are known as

a) Actual parameters               b)Formal parameters




49)
#include<stdio.h>
void main()
{
char *fun();
char *s;
s=fun();
printf("%s",s);
}

char *fun()
{
return("Hello");
}


o/p:Hello



50)
The range of unsigned integers is _________


51)

prefix to infix
postfix to infix



52)Which is initialized as zero

1)global variable                      2)static variable
3)register variable                    4)extern variable

a)(1) and (2)                b) (1) and (3)

c) (1),(2)and (3)           d) (1),(2),(3) and (4)


Ans:  a


53)
which statement used to read from file

1)fgets             2)fread                        3)fscanf           4)sscanf


54)
#include<stdio.h>
fun1()
{
int a=5;
static int b=5;
a++;
b++;
printf("%d  ",a);
printf("%d\n",b);
}
void main()
{
fun1();
fun1();
}

o/p:

6 6
6 7


55)
In what aspect linked list is efficient than array

1)Insertion                   2)deletion                    3)Traversal     

a)1 and 2                     b)3 only           c)2 and 3 only

Ans:(a)



56)

#include<stdio.h>

void main()
{
int i;
for(i=16/3;i<5;i++)
printf("%d",i);
}

o/p:

no output


57)

#include<stdio.h>
void main()
{
int a;
a=9/4.5;
printf("%d",a);
}

Ans: 2

58)

#include<stdio.h>
#define TRUE 1
#define FALSE 0
void main()
{
if(TRUE)
printf("True");
else
printf("False");
}

o/p:
True


59)


#include<stdio.h>
void main()
{
char str1[]="Hello";
char str2[]="Hello";
if(str1==str2)
printf("True");
else
printf("False");
}

o/p:false


60)

Which of the following is correct
a) To read a character by character in files getc is used.
b) To read a character by character in files fgetc is used.
c) To read a line by line in a file gets is used.
d) To read a line by line in a file fgets is used.

Ans:(a),(b) and (d)


61)
#include<stdio.h>
itn one_d[]={1,2,3};
void main()
{
int *ptr;
ptr=one_d;
ptr+=3;
printf("%d",*ptr);
}
/*#include<stdio.h>

void main()
{
            int array[] = {10,20,30,40,50};
            int *p;

            p = &array+4;

            for (;p>=array; p--)
            {
                        printf ("%d \n", *p);
            }
}*/
//______________________________________________________________________________

/*#include<stdio.h>

struct city
{
            char name[10];
            char *address;
};

struct details
{
            struct city c;
};

void main()
{

            struct details *d1;

            scanf("%s",d1->c.address);
}*/

//______________________________________________________________________________

/* A complete binary tree has
 statement 1: non-leaf nodeshave two child
 statement 2: All left subtree values less than root and root less than right tree

 Which is correct

 1 alone
 2 alone
 either 1 or 2
 neither 1 nor 2*/

//______________________________________________________________________________

/* In doubly linked list, to add a new element in the tail node
            1. nd->next = NULL:
            2. nd-> prev->next = tail;
            3 nd - > prev = tail;

            which order is correct
            1 2 3
            3 2 1
            3 1 2 */

//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
int  c[] ={2.8,3.4,4,4.6,7.5};

            int  j, *p=c, *q = c;

            for (j=0; j<5; j++)
            {
                        printf("%d", *c);
                        ++q;
            }

            for (j=0; j<=5; j++)
            {
                        printf("%d", *p);
                        ++q;
            }
}*/
//______________________________________________________________________________

/* Which of the following is correct

1. signed char range is -128 to 127
2. unsigned char range is 0 to 255
3. int by default is short int
4. short int by default is signed short int */

//______________________________________________________________________________

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

void main()
{
            int i,n;

            char *x = "OOAD";
            n = strlen(x);

            *x = x[n];

            for(i=0; i <n; ++i)
            {

                        printf ("%s \n", x);
                        x++;
            }

}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
            int i, j;
            for(i=0; i <2; i++)
            {
                        for(j=0; j<5; j++)
                        {
                        if(i==j)

                                    break;
                                    printf ("wipro");
                        }
            }
}*/

//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
            int i=2;
            switch(i)
            {
                        case 2:
                                                            printf ("Case2");

                        case 1:
                                                            printf ("Case1");
                                                            break;
            }
}*/

//______________________________________________________________________________


/* When pointer is assign to null pointer what will be the output
a. compile Error
b. runtime error while acessing the pointer
c. some output*/

//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
            int *p, j;
            ????

            *p = 35;
            printf ("%d", j);
}*/
//______________________________________________________________________________

/*#include<stdio.h>

aaa()
{
            printf("hi");
}

bbb()
{
            printf ("Hello");
}

ccc()
{
            printf("bye");
}

void main()
{
            int (*ptr[3])();
            ptr[0] = aaa;
            ptr[1] = bbb;
            ptr[2] = ccc;


            ptr[2]();
}*/
//______________________________________________________________________________

/*#include<stdio.h>

#define wipro main

wipro()
{
            printf ("main");
}

void main()
{
            wipro();
}*/

//______________________________________________________________________________

/*#include<stdio.h>

#define output(int) printf ("%d", int);

void main()
{
            int a=2,b=3;
            output(a);
            output(b);
}*/

//______________________________________________________________________________

/*#include<stdio.h>

#define wipro printf

main()
{
            wipro("Hai");
}*/

//______________________________________________________________________________

/* Which one of the following statements is true for binary searc tree
1. root is less than left & right sub tree
2. root is less than left sub tree but greater than right sub tree*/

//______________________________________________________________________________

/* The Range fo unsigned integer is _____________________________*/

//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
            auto int i=0;
            static int j=0;
            extern int k =0;
            register int l=0;

            i++;
            j++;
            k++;
            l++;

            printf ("%d %d %d", i, j,l);
}*/

//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
            const char a="b";
}*/
//______________________________________________________________________________


/*#include<stdio.h>
void main()
{
            int i=10;

            while(++i>10)
            {
                        printf ("something");
            }
}*/

//______________________________________________________________________________

/*#include<stdio.h>
define mul(a) (a) * (a); /*They will ask u what will be the define statement to
get the output as hundred and the define statement have four opitons. This is
correct option to get the output*/

/*void main()
{
            int result;
            result = mul(10);

            printf ("%d", result);
}*/

//______________________________________________________________________________

/*#include<stdio.h>

struct a
{
            int no;
            int *no1;
            int *no2;
} *a1;

void main()
{
            printf ("%d %d %d %d", sizeof(a1->no),sizeof(a1->no1), sizeof(*a1), sizeof(a1));
}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
            static int a[5];

            int i;

            for(i=0; i<5; i++)
            {
                        printf ("%d", a[i]);
            }
}*/

//______________________________________________________________________________

/*#include<stdio.h>

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

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
int x,y=6;
x=y+NULL;
printf("%d",x);
} */
//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
static int arr[12];
printf("%d",sizeof(arr));
} */
//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
float a[]={1.2,3.4,5.7,12.3};
int i;
for(i=0;i<=5;++i)
printf("%f   ",a[i]);
}*/
//______________________________________________________________________________

//A user-defined function returns a pointer (yes/No)

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
char *p="hello";
char q[]={'h','e','l','l','o'};
printf("%d  %d",sizeof(*p),sizeof(*q));
}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
int i=0;
while()
{
switch(i)
{
case 3<2:
printf("Hi");
break;
case 3>2:
printf("Hello");
break;
default:
printf("welcome");
}
++i;
}
}*/
//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
int i=0;
while(i<3)
{
switch(i)
{
case 1:
printf("case1");

case 2:
printf("case2");
break;
default:
printf("Default");
}
++i;
}
}*/
//______________________________________________________________________________


/*#include<stdio.h>
void main()
{
char str1[]="Hello";
char str2[]="Hello";
if(str1==str2)
printf("\nEqual");
else
printf("\nNot equal");

}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
int i;
for(i=2;i=0;i--)
{
printf("%d",&i);
}
}*/
//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
            int i=5;

            printf ("%d", ~i);
}*/

//______________________________________________________________________________

/*#include<stdio.h>

void main()
{
int i=10;
printf("%d  ",i=50);
}*/
//______________________________________________________________________________

/*#include<stdio.h>
#define HELLO "hi"
void main()
{
printf("HELLO");
}*/
//______________________________________________________________________________


/*#include<stdio.h>

struct person
{
char *name;
char *age;
char *c;
};
struct emp
{
int a;
struct person *addr;
};

void main()
{
struct emp *e1;
printf("%d",sizeof(e1));

}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
int i;
i=10/4;
printf("%d",i);

}*/

//______________________________________________________________________________
/*#include<stdio.h>
void main()
{
int a[3][4]={1,2,3,4,5,6,7,8,9};
printf("%d ",a[2][1]);
}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{

int array[]={10,20,30,40,50},*p;
p=&array[0] + 4;  //p=array+4
for(;p>=array;p--)
printf("%d   ",*p);

}*/

//______________________________________________________________________________

/*#include<stdio.h>
#define wipro main
void wipro()
{

printf("main");

}*/

//______________________________________________________________________________

/*#include<stdio.h>
void main()
{
int a=10,b=10;
a+=1;
printf((a>b)?"hi":"hello");
}*/

//______________________________________________________________________________

/*#include<stdio.h>
struct emp
{
int i;
char name[15];
};

void main()
{
struct emp e1={1,"hi"},*e2;
e2=&e1;
if(e1==e2)
printf("\nstructures are equal");
else
printf("\nstructures are not equal");
}*/

//______________________________________________________________________________


6.      The size of long double is
a. 8 bytes               b. 10 Bytes      c. Compiler Dependent          
d. There is no datatype called long double.
Ans::b
7.      What is the output of the following:
unsigned  i=32768;
void main()
{
                             printf("%d",i);
   }

b.      32768
c.       -32768         
d.      Error
e.       None of the above
Ans::b
  
8.      How many times Wipro Technologies printed in the following code:
 for(i=0;i<5;i++)
   for (j=0;j<5;j--)
    {
               if (i==j) break;
               printf(“Wipro Technologies”);
   }

a.       4 times
b.      Error
c.       Infinite loop
d.      Not predictable
Ans::c
9.      What is the output of the following
int i;
void main()
{
                     static int i=3;
                     printf("%d",i);
}

e.       3
f.       Multiple declaration (since I is static)
g.      0
h.      None of the above
Ans::a(3)
10.  What is the output of the following:
main()
{
      void change(char *);
      char *t="test";
      change(t);
      printf("%s",t);

}
void change(char *t)
{
      char *ab="new test";
      *t=*ab;
}
  1. new test
  2. test
  3. nest
  4. None of the above
Ans::c
6. main()
    {
       char *fun();
       printf("%s",fun());
   }
      char * fun()
    {
      char buffer[]=”Hello World”;
      return buffer;
    }  
                 
 
  a) hello world
  b) Compiler error
  c) Garbage Value
    d) None of the above
ans::c//if static char buffer is used it would have worked
11.  main()
{
   int  a=10,*p=&a,*q=p;
                  *q++;//valid
   printf(“%d %d %d”,a,*p,*q);
}
a.       11 11 11
b.      10 10 11
c.       Garbage value;
d.      Error
Garbage value//actaually 10 10 garbage
Ans::c
12.  #define c(a) a*a
#define c(b) b+b
void main()
{
 printf(“%d”,c(10));
}

e.       100
f.       20
g.      400
h.      Error
Ans::f
13.  void rec(int);
void main()
{
       rec(3);
}
void rec(int n)
{
    if (n<=0)
    return;
    rec(n-1);
    printf(“%d”,n);
    rec(--n);
            }
  1. 1 2 1 3 1 2 1
  2. 0 1 2 0
  3. Infinite loop
  4. Error
Ans::a
14.  int z, x=5,y=-10,a=4,b=2;
z=x++ - --y * b / a;
What number will z in the sample code above contain?
a. 5
b. 6
c. 10
d. 11
ans::c

10. char* myFunc (char *ptr)
{
 ptr += 3;
 return (ptr);
}


int main()
{
 char *x, *y;
 x = "HELLO";
 y = myFunc (x);
 printf ("y = %s \n", y);
 return 0;
}
What will print when the sample code above is executed?
a. y = HELLO
b. y = ELLO
c. y = LLO
d. y = LO
Ans::d
11. What would be the output?
 void main()
{
printf("%s",7["wipro infotech");
}
 
a.       f
b.      Garbage value
c.       fotech
d.      Error
Ans::b Garbage value //used as”wipro infotech”+7
12. Predict the output
char p[]="hello";
char q[]={'h','e','l','l','o'};
printf("%d  %d",sizeof(p),sizeof(q));

  1. 5 5
  2. 6 6
  3. 6 5
  4. 5 6
Ans::c
13. What would be printed:
    #include<stdio.h>
               int i=0;
               void main()
               {
               while(i)
               {
                               switch(i)
                               {
                               Case 3<2:
                                              printf("Hi");
                                              break;
                               case 3>2:
                                              printf("Hello");
                                              break;
                               default:
                                              printf("welcome");
                               }
                               ++i;
                               }
               }
 
b.      Hi
c.       Welcome
d.      No output
e.       Error
Ans::c
14. struct addr
{
char city[5];
char street[5];         
};
struct emp
{
char name[20];
int empno;
struct addr *a;
};
 
struct emp *pemp;
 
How will you access city from the *pemp;
a.       pemp->a->city
b.      pemp->*a.city
c.       pemp->a.*city
d.      All the above.
Ans::a //rest invalid
15. #include<stdio.h>
int get();
void main()
{
int x=20;
x=get();
printf("%d ",x);
}
 
int get()
{
return(60);
}
 
b.      60
c.       Garbage
d.      Error
e.       None of the above
Ans::a
16. What would be the out put of the following
void main()
{
int a=10,b=20,c=30;
a++ || b-20 && ++c;
printf("%d %d %d",a,b,c);
}
a.       11 20 31
b.      11 0 30
c.       11 20 30
d.      Error
Ans::c
17. What will be the output of the following program :
            void main()
            {
              printf("Hi!");
              if (-1)
                printf("Bye");
            }
(a)No Output              (b)Hi!                                      (c)Bye                         (d)Hi!Bye
Ans::d
18. void main()
            {
              printf("Hi!");
              if !(0)
                printf("Bye");
            }
(a)Compile-Time error (b)Hi!                                      (c)Bye                         (d)Hi!Bye
Ans::a
19. void main()
            {
              printf("Hi!");
              if (-1+1+1+1-1-1-1+(-1)-(-1))
                printf("Bye");
            }
(a)No Output              (b)Hi!                                      (c)Bye                         (d)Hi!Bye
Ans::d
20. void main()
            {
              int a=1,b=2,c=3,d=4,e;
              if (e=(a & b | c ^ d))
                  printf("%d",e);
            }
(a)0                              (b)7                                          (c)3                              (d)No Output
Nas::
21. auto int a=5;
            void main()
            {
              printf("%d",a);
            }
(a)Compile-Time error (b)Run-Time error                   (c)5                              (d)Unpredictable
Ans::a//auto cannot be declared outside any fuction
22.  main()
            {
              int a=1;
              if (a)
                 printf("Test");
              else;
                 printf("Again");
            }
(a)Again                      (b)Test                                     (c)Compile-Time Error            (d)TestAgain
Ans::b
23. 
void main()
            {
              float i;
              for (i=0.1; i<0.4; i+=0.1)
                  printf("%.1f",i);
            }
(a)0.10.20.3                 (b)Compile-Time Error                        (c)Run-Time Error       (d)No Output
Ans::a
 
24.Point out the error if any
 #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
            struct xx *p;
};//name sud be given….
struct yy *q;
};
}
 
  1. Compile time error
  2. Run time error
  3. No error.
  4. Compiler dependent
ans::a

5. Heap

1) is a region from where memory is  allocated
2) lies between you program and the stack
3) is a finite area
4) all of the above
Ans::4
26. Predict the output
int a = 4, b = 7,c; c = a = = b; printf("%i",c);

a) 0
b) error
c) 1
d) garbage value
ans::error//= = would not work == will do
27. What will be the output of the following statements
?
int a[2][2] = { 3,2,5,4 };
printf("%d",*(*(*(a))));

a) error
b) 3
c) garbage value
d) 2
Ans::a
28.
Which of the functions is most apt for reading a multi-word ?

a) puts()
b) gets()
c) scanf()
d) vsscanf()
Ans::b
29. What will be the output of the following program ?

#include<stdio.h>
#include<math.h>
void main()
{
int n; char *str = "324.89";
n = atoi(str); printf("%d",n);
}

a) 300
b) 324
c) 32489
d) 89
Ans::324
30. #include<stdio.h>
void main()
{ printf("%d"); }

a) error
b) no output
c) %d
d) 0
Ans::d
31. #include<stdio.h>
void main()
{
int a = 36, b = 9;
printf("%d",a>>a/b-2);
}

a) 9
b) 7
c) 5
d) none of these
Ans::a
32. #include<stdio.h>
      void main()
      {
        int a,b;
        void small(int,int);
        printf("Enter 2 numbers\n");
        scanf("%d %d",&a,&b);
      }
      void small(int x,int y)
      {
         if (x<y)
           printf("A is less than B"');
         else
           printf("B is less than A");
      }
If a=10, b=10 What is the output

  1. B is less than A
  2. A is less than B
  3. Error
  4. No output
Ans::d
33. swap(int *a,int *b)
{
int *t;
t=a;
a=b;
b=t;
}

void main()
{
int a=10,b=20;
swap(&a,&b);
printf(“%d %d”,a,b);
}

  1. 10 20
  2. 20 10
  3. Error
  4. Garbage value
Ans::a
34. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0')
 ++*++p;
printf("%s   %s",p,p1);
}

    1. ibj!gsjfoet
    2. hbj!gsjfoet
    3. hbj!gsjfoet hbj!gsjfoet
    4. None of the above
Ans::d//abnormal program termination
35. main( )
{
 char  *q;
 int  j;
 for (j=0; j<3; j++) scanf(“%s” ,(q+j));
 for (j=0; j<3; j++) printf(“%c” ,*(q+j));
 for (j=0; j<3; j++) printf(“%s” ,(q+j));
}
If the input given are Wipro Technologies Chennai
What will be the output

  1. WTChennai TChennai Chennai
  2. Chennai Chennai Chennai
  3. Wipro Technologies Chennai
  4. None of the above
Ans::d
36. main()
{
 int  i, n;
 char *x = “OOAD”;
 n = strlen(x);
 *x = x[n];
 for(i=0; i<n; ++i)
   {
printf(“%s\n”,x);
x++;
   }
 }

  1. OOAD
OAD
AD

  1. OAD
AD
D

  1. No output
  2. None of the above
Ans::b
37. #define FALSE -1
            #define TRUE   1
            #define NULL   0
            main() {
               if(NULL)
                        puts("NULL");
               else if(FALSE)
                        puts("TRUE");
               else
                        puts("FALSE");
               }

  1. TRUE
  2. FALSE
  3. TRUE FALSE
  4. Error
Ans::a
38. main()
{
              int i=5,j=6,z;
              printf("%d",i---j);
             }

  1. -1
  2. Error
  3. 0
  4. None of the above
Ans::a
39. main()
{
 char *p;
 int *q;
 long *r;
 p=0;
q=0;
r=0;
 p++;
 q++;
 r++;
 printf("%p...%p...%p",p,q,r);
}

  1. 0001 0002 0004
  2. 0000:0001 0000:0002 0000:0004
  3. 1 2 4
  4. Error
Ans::a//inc by their type value in p,q r set to zero
40. # include<stdio.h>
aaa() {
  printf("hi");
 }
bbb(){
 printf("hello");
 }
ccc(){
 printf("bye");
 }
main()
{
  int (*ptr[3])();
  ptr[0]=aaa;
  ptr[1]=bbb;
  ptr[2]=ccc;
  (*ptr)();
}

  1. hi
  2. hello
  3. bye
  4. Error
Ans::hi

1) Which of the following is a compound assignment statement?
            a)a=b
            b) a=b=c
            c) a+=b
            d) a=b;b=c;
ans::c
2) given that the file is being read using fgetc command,as ch =fgetc(fp),then what is the condition to check for the end of the file
            a) ch!=EOF
            b) ch!=NULL
            c) ch==NULL
            d) ch=='\0'
ans::a
3) which of the following accepts only the specified number of characters from a file
            a) fgets
            b) fread
            c) fputc
            d) fputs
ans::a
4) which of the following is the best for getting a string with space from the standard input
            a) gets
            b) getc
            c) fgets
            d) puts
ans::fgets//gets
5)how to represent a character pointer named 'message' pointing to the array"hello"
            a) char message="hello"
            b) char message[ ]="hello"
            a) char *message="hello"
            a) char *message[ ]="hello"
ans::c
6) which data structure is best for searching an element in the given list
            a) arrays
            b) single linked list
            c) doubly linked list
            d) binary search trees
ans::d
7) assume that integer is 4 bytes,pointer as 4 byter and character as 1 byte,then predict the output
            struct student
            {
               int a;
               char name[10];
               int *p;
            }s1,*s2;
            printf("%d%d",sizeof(s1),sizeof(*s2));
           
                        a) 18,18
                        b)18,4
                        c) 4,18
                        d) 4,4
ans::a
8) what would the statement strcmp("Astring","Astring"); return?
            a) 0
            b) <1
            c)>1
            d) -1
ans::a
9) which statement is used to compare the two strings          ?
            a) strcmp
            b)strcompare
            c) stringcompare
            d) str_cmp
ans::a
10) int fun(int x)
       {
          int y=55;
            return((x-y)?y:x);
      }
     main()
      {
            int a=20;
             fun(a);
         printf("%d",y);
     }

ans::error
11) main()
        {
            static int a[10]={1,2,3,4,5};
                int i;
             for(i=0;i<10;i++)
            printf("%d ",a[i]);
        }
ans::1 2 3 4 5 0 0 0 0 0           

12) main()
       {
           char *y;
             y=x();
            printf("%s",y);
       }
    char *x()
      {
             char result[ ]="Hello";
             strcpy(result,"anything good");
             return result;
       }
ans::buffer die after function get lost
13) The post order is 5,20,10.what will be the inorder?
            A)5,10,20
            b) 20,5,10
            c) 20,10,5
            d) none of the above
ans::a
14) int fact(int x)
         {
              ??????
            return(x*fact(x-1));
         }
        main()
        {
            fact(5);
        }
     what would be replaced in terms of ???????
            a) if(x==0) return 0;
            b) if(x==1) return 1;
            c) if(x==2) return 2;
            d) none of the above
ans::b

15) Allocating a 2 blocks of memory for 'n' intgers is by using
            a) malloc
            b) calloc
            c) both malloc and calloc
            d) none of the above
ans::b
16) In queue using linked list, which is correct?
            a) both insertion and deltionis made at the front end
            b) insertion is made at the beginning and deletion is made at the last
            c) insertion is made at the last and deletion is made at the beginning
            d) both insertion and deltionis made at the back end
ans::c
17) main()
        {
             int i=10;
            printf("%d",i==10);
        }
ans::1
18) main()
       {
            char c='p';
            printf("%c",c);
       }
ans::p
19) main()
         {
             int i=0;
            while(i<3)
              {
                  switch(i)
                      {
                          case 3>2:
                                printf("case1"):
                                break;
                          case 3<2:
                                printf("case2");
                                break;
                          defalut:         
                                    printf("default");
                                break;
                          }
                    i++;
              }
ans::case2case1

20) which is correct?
            a) unsigned char short
            b) unsigned short char
            c) short unsigned char
            d)noneof the above
ans::b
21)     void fun(char *str)
        {
              char *str1="hai";
                     str=str1;
        }
        main()
        {
             char *str="Hello";
             fun(str);
             printf("%s",str);
        }
ans::hello
22) struct city
        {
             char *name[20];
              int age;
        }*s;
 how to allocatethe memory for the member 'name'?
s->name[]=(char*)

23) what is the header file to be included for doing mathematical calculations?

24) what is the way to declare a float pointer?
float *f;
25) what kind of error   does the syntax error is?

26)  float fun( f1)
          {
               return(f1*f1);
          }
        main()
             {
                 float f1=3.25;
                  fun(f1);
                   printf("%f",f1);
             }
 ans::3.25//also f1 will take int value only
27) for(i=0;i<2;i++)
        {
           for(j=0;j<5;j++)
            {
            if(i==j)
            break;
            printf("wipro");
            }
         }
how many times would wipro to be printed?

ans::wipro will be printed only one times.

28) main()
         {
              FILE *fp;
                        char data[100];
              printf("Enter the file name");
                gets(data);
             ????
             fclose(fp);
        }             
fp=fopen(data,"r");
what would be replaced for ???? to open a file in a read mode


29) main()
        {
           int 5[a]={10,20,30,40,50};
             int *p;
          p=a[2];
            printf("%d",2[a]);
       }
error
30)   which of these isn an infinite loop          ?
            i) for(;;);
            ii)for(i=1;;i++);
            iii) for(i=0;i<=5;i++)
                   { --i;}

                        a) i,ii only
                        b) i only
                        c)all the three
                        d) none of the above
ans::c
31)which of these is replaced by a switch block?
            a)  while loop
            b) do while
            c) for loop
            d)else if


32) void disp(char *string)
         {
            printf("%d\n",string);
            printf("%s\n",string);
        }
      void main()
       {
           char string[ ]="Hello world";
               printf("%d\n",string);          
               disp(string);
       }


33) char *gxxx()
        {
             static char x[1024];
             printf("%s\n",x);
                 return x;
        }
        void main()
        {
              char *g="string";
                  strcpy(gxxx(),g);
                  g=gxxx();
                  strcpy(g,"old string");
                  printf("%s\n",gxxx());
        }
ans::old string
34) main()
       {
            char s[ ]="\12345s\n";
            printf("%d\n",sizeof(str));
       }
ans::6
35)    main()
           {
               char *k[ ]={" Good Morning","Good Evening","Good night"};
            printf("%s\n",k[0]);
            printf("%s\n",*(k+1));
           }
ans::Good Morning Good Evening

36) which one of the following is incorrect? 
           a) signed char a;
            b)char signed a;
            c) char a signed;
            d) none of  the above
ans::c

37) all the local variables are stored in -----------------
            a) stack
            b) heap
            c) queue
            d) none
ans::a
38) Once you call a function,all the return addresses are stored in ----------------
            a) stack
            b) heap
            c) queue
            d) none
ans::a
39) Which of the following is true about binary tree
            i) all nodes except leaf node has exactly two child
            ii) root node is greater than the left sub tree and lesser than the right sub tree.
                        a) i only
                        b)ii only
                        c) both i and ii
                        d) neither i nor ii        
ans::b
40) Which of the following is true about complete binary tree
            i) all nodes except leaf node has exactly two child
            ii) root node is greater than the left sub tree and lesser than the right sub tree.
                        a) i only
                        b)ii only
                        c) both i and ii
                        d) neither i nor ii        
            ans::c
41)   struct node
            {
                int data;
                struct node *left,*right;
            };
suppose start and end are the pointers pointing to the beginning and ending node reapectively.then,
what will be the output of the following snippet
front=start;
back=end;
while(back!=NULL)
{
    printf("%d",back->data);
            back=back->left;
}
reverse printing

42)   struct node
            {
            int data;
            struct node *left,*right;
            };
suppose start and end are the pointers pointing to the beginning and ending node reapectively.then,what will be the output of the following snippet
front=start;
back=end;
while((front!=back)&&(back->left!=front))
{
      temp=front->data;
      front->data=back->data;
      back->data=temp;
}


43) the declaration of the pinter to an array ofint having the name iptr is -------------------
            a) int *iptr
            b) int &iptr
            c) int *&iptr
            d)iptr *int

ans::a
44) int one_d={0,1,2};
       main()
        {
            int *ptr;
            ptr=one_d;
            ptr+=3;
            printf("%d",*ptr);
        }
ans::error
45)  struct a
         {
            char *b;
            char *c;
            char *d;
      };
struct e
{
  char *f;
   struct a *g;
}abc;
printf("%d",sizeof(abc));

ans::4

46)  struct a
         {
            char *b;
            char *c;
            char *d;
      };
struct e
{
  char *f;
   struct a g;
}abc;
printf("%d",sizeof(abc));
ans::8

47)#define wipro main
        wipro()
        {
            printf("main");
         }
ans::main
48)  void prod(int x,int y,int z)
{
       int p;
       p=x*y*z;
       printf("%d",p);
}
void main()
{
 int a=3,b=4,c=5;
prod(a,b,c);
}
49)  int meq();
void main()
{
printf("Hai");
meq();
printf("Hello");
}
meq()
{
printf("Bye");
}
ans::HaiByeHello
49)  void main()
{
char *p="welcome";
char q[ ]={'w','e','l','c','o','m','e'};
printf("%d %d",sizeof(*p),sizeof(*q));
}
ans::11
50)  The size of the doubly linked list is always greater than the single linked list
            a) true
            b) false


51)  char *ptr="abcdefgh";
char *sptr;
sptr=ptr+5;
printf("%s",sptr);

ans::fgh
52) If the integer occupies 2 bytes then short int will take how many bytes?

53) In C, syntax error is generated by ---------------------
            a) compiler
            b) Interpreter
            C) linker
            d) none

54)  char *ptr="Madam";
char *sptr=ptr+4;
while(sptr>=ptr)
{
  printf("%c",*sptr);
sptr--;
}
ans::madaM

55) void main()
{
int i;
i=10/20;
printf("%d",i);
}
ans::0

56) The arguments in a function call is known as ---------------------
            a) formal arguments
            b) actual arguments

57)  main()
{
int i;
for(i=0;i<10;i++);
printf("%d",i);
}
ans::10

58) int i=10;
main()
{
int i=20;
{
int i=30;
printf("%d",i);
}
printf("%d",i);
}
ans::3020

59) void fun();
main()
{
fun();
}
void fun()
{
   printf("good");
}
ans::good

60) void main()
{
   int i=10;j=20,k=30,l=40,m;
int *a[4];
a[0]=&i;
a[1]=&j;
a[2]=&k;
a[3]=&l;
for(m=0;m<4;m++)
printf("%d",*a[m]);
}
ans::10203040

61) if the insertion is made only at the beginning then which data structure is used
            a) array
            b) stack
            c) queue
            d) linked list

62) to access the 4th element in the array 'num' we need -------------
            a) num[4]
            b) num[1]
            c)num[3]
            d) none of the above


63) void main()
{
     char *a[ ]={"Dharma","Hewlett packard","New city","ibm"};
     char **ptr=a;
     printf("%s",++*p);
     printf("%s",*p++);
     printf("%s",*p);
}
ans::harmaharmaHewlett packard

64)







                        C  Questions

Note : All the programs are tested under Turbo C/C++ compilers. 
It is assumed that,
Ø       Programs run under DOS environment,
Ø       The underlying machine is an x86 system,
Ø       Program is compiled using Turbo C/C++ compiler.
The program output may depend on the information based on this assumptions (for example sizeof(int) == 2 may be assumed).

Predict the output or error(s) for the following:

1.      void main()
{
            int  const * p=5;
            printf("%d",++(*p));
}
Answer:
                        Compiler error: Cannot modify a constant value.
Explanation:   
p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".

2.      main()
{
            char s[ ]="man";
            int i;
            for(i=0;s[ i ];i++)
            printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}
Answer:
                        mmmm
                       aaaa
                        nnnn
Explanation:
s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally  array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is same as s[i]. i[s] may be surprising. But in the  case of  C  it is same as s[i].

3.      main()
{
            float me = 1.1;
            double you = 1.1;
            if(me==you)
printf("I love U");
else
                        printf("I hate U");
}
Answer:
I hate U
Explanation:
For floating point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value  represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double.
Rule of Thumb:
Never compare or at-least be cautious when using floating point numbers with relational operators (== , >, <, <=, >=,!= ) . 

4.      main()
            {
            static int var = 5;
            printf("%d ",var--);
            if(var)
                        main();
            }
Answer:
5 4 3 2 1
            Explanation:
When static storage class is given, it is initialized once. The change in the value of a static variable is retained even between the function calls. Main is also treated like any other ordinary function, which can be called recursively. 

5.      main()
{
             int c[ ]={2.8,3.4,4,6.7,5};
             int j,*p=c,*q=c;
             for(j=0;j<5;j++) {
                        printf(" %d ",*c);
                        ++q;     }
             for(j=0;j<5;j++){
printf(" %d ",*p);
++p;     }
}

Answer:
                        2 2 2 2 2 2 3 4 6 5
            Explanation:
Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.
           
6.      main()
{
            extern int i;
            i=20;
printf("%d",i);
}

Answer: 
Linker Error : Undefined symbol '_i'
Explanation:
                        extern storage class in the following declaration,
                                    extern int i;
specifies to the compiler that the memory for i is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name i is available in any other program with memory space allocated for it. Hence a linker error has occurred .

7.      main()
{
            int i=-1,j=-1,k=0,l=2,m;
            m=i++&&j++&&k++||l++;
            printf("%d %d %d %d %d",i,j,k,l,m);
}
Answer:
                        0 0 1 3 1
Explanation :
Logical operations always give a result of 1 or 0 . And also the logical AND (&&) operator has higher priority over the logical OR (||) operator. So the expression  ‘i++ && j++ && k++’ is executed first. The result of this expression is 0    (-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value of m is 1. The values of other variables are also incremented by 1.

8.      main()
{
            char *p;
            printf("%d %d ",sizeof(*p),sizeof(p));
}

Answer:
                        1 2
Explanation:
The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

9.      main()
{
            int i=3;
            switch(i)
             {
                default:printf("zero");
                case 1: printf("one");
                           break;
               case 2:printf("two");
                          break;
              case 3: printf("three");
                          break;
              } 
}
Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.

10.  main()
{
              printf("%x",-1<<4);
}
Answer:
fff0
Explanation :
-1 is internally represented as all 1's. When left shifted four times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value be printed as a hexadecimal value.

11.  main()
{
            char string[]="Hello World";
            display(string);
}
void display(char *string)
{
            printf("%s",string);
}
            Answer:
Compiler Error : Type mismatch in redeclaration of function display
            Explanation :
In third line, when the function display is encountered, the compiler doesn't know anything about the function display. It assumes the arguments and return types to be integers, (which is the default type). When it sees the actual function display, the arguments and type contradicts with what it has assumed previously. Hence a compile time error occurs.

12.  main()
{
            int c=- -2;
            printf("c=%d",c);
}
Answer:
                                    c=2;
            Explanation:
Here unary minus (or negation) operator is used twice. Same maths  rules applies, ie. minus * minus= plus.
Note:
However you cannot give like --2. Because -- operator can  only be applied to variables as a decrement operator (eg., i--). 2 is a constant and not a variable.

13.  #define int char
main()
{
            int i=65;
            printf("sizeof(i)=%d",sizeof(i));
}
Answer:
                        sizeof(i)=1
Explanation:
Since the #define replaces the string  int by the macro char

14.  main()
{
int i=10;
i=!i>14;
Printf ("i=%d",i);
}
Answer:
i=0


            Explanation:
In the expression !i>14 , NOT (!) operator has more precedence than ‘ >’ symbol.  ! is a unary logical operator. !i (!10) is 0 (not of true is false).  0>14 is false (zero).

15.  #include<stdio.h>
main()
{
char s[]={'a','b','c','\n','c','\0'};
char *p,*str,*str1;
p=&s[3];
str=p;
str1=s;
printf("%d",++*p + ++*str1-32);
}
Answer:
77       
Explanation:
p is pointing to character '\n'. str1 is pointing to character 'a' ++*p. "p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10, which is then incremented to 11. The value of ++*p is 11. ++*str1, str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.
 Now performing (11 + 98 – 32), we get 77("M");
 So we get the output 77 :: "M" (Ascii is 77).

16.  #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8}  };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
}
Answer:
SomeGarbageValue---1
Explanation:
p=&a[2][2][2]  you declare only two 2D arrays, but you are trying to access the third 2D(which you are not declared) it will print garbage values. *q=***a starting address of a is assigned integer pointer. Now q is pointing to starting address of a. If you print *q, it will print first element of 3D array.
           
17.  #include<stdio.h>
main()
{
struct xx
{
      int x=3;
      char name[]="hello";
 };
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}
            Answer:
Compiler Error
Explanation:
You should not initialize variables in declaration

18.  #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
            struct xx *p;
};
struct yy *q;
};
}
Answer:
Compiler Error
Explanation:
The structure yy is nested within structure xx. Hence, the elements are of yy are to be accessed through the instance of structure xx, which needs an instance of yy to be known. If the instance is created after defining the structure the compiler will not know about the instance relative to xx. Hence for nested structure yy you have to declare member.

19.  main()
{
printf("\nab");
printf("\bsi");
printf("\rha");
}
Answer:
hai
Explanation:
\n  - newline
\b  - backspace
\r  - linefeed

20.  main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
Answer:
45545
Explanation:
The arguments in a function call are pushed into the stack from left to right. The evaluation is by popping out from the stack. and the  evaluation is from right to left, hence the result.

21.  #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Answer:
64
Explanation:
the macro call square(4) will substituted by 4*4 so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64
 
22.  main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s   %s",p,p1);
}
Answer:
ibj!gsjfoet
            Explanation:
                        ++*p++ will be parse in the given order
Ø       *p that is value at the location currently pointed by p will be taken
Ø       ++*p the retrieved value will be incremented
Ø       when ; is encountered the location will be incremented that is p++ will be executed
Hence, in the while loop initial value pointed by p is ‘h’, which is changed to ‘i’ by executing ++*p and pointer moves to point, ‘a’ which is similarly changed to ‘b’ and so on. Similarly blank space is converted to ‘!’. Thus, we obtain value in p becomes “ibj!gsjfoet” and since p reaches ‘\0’ and p1 points to p thus p1doesnot print anything.

23.  #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}
Answer:
50
Explanation:
The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken.

24.  #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}
Answer:
100
Explanation:
Preprocessor executes as a seperate pass before the execution of the compiler. So textual replacement of clrscr() to 100 occurs.The input  program to compiler looks like this :
                        main()
                        {
                             100;
                             printf("%d\n",100);
                        }
            Note:  
100; is an executable statement but with no action. So it doesn't give any problem

25.  main()
{
printf("%p",main);
}
Answer:
                        Some address will be printed.
Explanation:
            Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.

27)       main()
{
clrscr();
}
clrscr();
           
Answer:
No output/error
Explanation:
The first clrscr() occurs inside a function. So it becomes a function call. In the second clrscr(); is a function declaration (because it is not inside any function).

28)       enum colors {BLACK,BLUE,GREEN}
 main()
{
 
 printf("%d..%d..%d",BLACK,BLUE,GREEN);
  
 return(1);
}

Answer:
0..1..2
Explanation:
enum assigns numbers starting from 0, if not explicitly defined.

No comments:

Post a Comment