Search here

Custom Search

5/28/2012

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


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


Part 7:-



1. main()
{
            float me = 1.1;
            double you = 1.1;
            if(me==you)
printf("Hello");
else
                        printf("Welcome");
}

1. Answer:
Welcome
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 (== , >, <, <=, >=,!= )


2. main()
{
            int i=3;
            switch(i)
             {
                default:printf("zero");
                case 1: printf("one");
                           break;
               case 2:printf("two");
                          break;
              case 3: printf("three");
                          break;
              } 
}

2. Answer :
three
Explanation :
The default case can be placed anywhere inside the loop. It is executed only when all other cases doesn't match.



3. main()
{
int i=10;
i=!i>14;
printf ("i=%d",i);
}

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



4. #include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
 {
 case 1:  printf("GOOD");
                break;
 case j:  printf("BAD");
               break;
 }
}
4. Answer:
Compiler Error: Constant expression required in function main.
Explanation:
The case statement can have only constant expressions (this implies that we cannot use variable names directly so an error).
            Note:
Enumerated types can be used in case statements.


5. main()
{
int i;
printf("%d",scanf("%d",&i));  // value 10 is given as input here
}

5. Answer:
1
Explanation:
Scanf returns number of items successfully read and not 1/0.  Here 10 is given as input which should have been scanned successfully. So number of items read is 1.


6. main()
{
int i=0;

for(;i++;printf("%d",i)) ;
printf("%d",i);
}


6. Answer:
            1
Explanation:
before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).



7. main()
            {
            int i=-1;
            +i;
            printf("i = %d, +i = %d \n",i,+i);
            }

7. Answer:
 i = -1, +i = -1
Explanation:
Unary + is the only dummy operator in C. Where-ever it comes you can just ignore it just because it has no effect in the expressions (hence the name dummy operator).



8. main()
            {
            char not;
            not=!2;
            printf("%d",not);
            }

8. Answer:
0
Explanation:
! is a logical operator. In C the value 0 is considered to be the boolean value FALSE, and any non-zero value is considered to be the boolean value TRUE. Here 2 is a non-zero value so TRUE. !TRUE is FALSE (0) so it prints 0.



9. main()
            {
            int k=1;
            printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
            }

9. Answer:
1==1 is TRUE
Explanation:
When two strings are placed together (or separated by white-space) they are concatenated (this is called as "stringization" operation). So the string is as if it is given as "%d==1 is %s". The conditional operator( ?: ) evaluates to "TRUE".



10. main()
            {
            int y;
            scanf("%d",&y); // input given is 2000
            if( (y%4==0 && y%100 != 0) || y%100 == 0 )
                 printf("%d is a leap year");
            else
                 printf("%d is not a leap year");
            }

10. Answer:
2000 is a leap year
Explanation:
An ordinary program to check if leap year or not.



11. main()
            {
            int i=-1;
            -i;
            printf("i = %d, -i = %d \n",i,-i);
            }

11. Answer:
i = -1, -i = 1
Explanation:
-i is executed and this execution doesn't affect the value of i. In printf first you just print the value of i. After that the value of the expression -i = -(-1) is printed.



12. int i;
            main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
                        printf("%d--",t--);
                        }
            // If the inputs are 0,1,2,3 find the o/p

12. Answer:
            4--0
                        3--1
                        2--2     
Explanation:
Let us assume some x= scanf("%d",&i)-t the values during execution
                        will be,
          t        i       x
          4       0      -4
          3       1      -2
          2       2       0


         
13. main(){
  int a= 0;int b = 20;char x =1;char y =10;
  if(a,b,x,y)
        printf("hello");
 }

13. Answer:
hello
Explanation:
The comma operator has associativity from left to right. Only the rightmost value is returned and the other values are evaluated and ignored. Thus the value of last variable y is returned to check in if. Since it is a non zero value if becomes true so, "hello" will be printed.




14. main(){
 unsigned int i;
 for(i=1;i>-2;i--)
                        printf("c aptitude");
}
14. Explanation:
i is an unsigned integer. It is compared with a signed value. Since the both types doesn't match, signed is promoted to unsigned value. The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.



15. void main()
{
            while(1){
                        if(printf("%d",printf("%d")))
                                    break;
                        else
                                    continue;
            }
}
15. Answer:
Garbage values
Explanation:
The inner printf executes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf  prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.



16. #include<conio.h>
main()
{
            int x,y=2,z,a;
            if(x=y%2) z=2;
            a=2;
            printf("%d %d ",z,x);
}


16. Answer:
Garbage-value 0
Explanation:
The value of y%2 is 0. This value is assigned to x. The condition reduces to if (x) or in other words if(0) and so z goes uninitialized.
Thumb Rule: Check all control paths to write bug free code.



17. main()
    {
       unsigned char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
    }

17. Answer
            infinite loop
Explanation
The difference between the previous question and this one is that the char is declared to be unsigned. So the i++ can never yield negative value and i>=0 never becomes false so that it can come out of the for loop.


18. main()
            {
       char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
 }
18. Answer:128
                        Behavior is implementation dependent.
Explanation:
The detail if the char is signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program will print –128 and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop.
Rule:
You can write programs that have implementation dependent behavior. But dont write programs that depend on such behavior.



19. main()
{
                        char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}


19. Answer:
A
Explanation:
Due to the assignment p[1] = ‘c’ the string becomes, “%c\n”. Since this string becomes the format string for printf and ASCII value of 65 is ‘A’, the same gets printed.




20. main()
{
                        int i=10,j=20;
            j = i, j?(i,j)?i:j:j;
                        printf("%d %d",i,j);
}
20. Answer:
10 10
Explanation:
                        The Ternary operator ( ? : ) is equivalent for if-then-else statement. So the question can be written as:
                        if(i,j)
                             {
if(i,j)
                             j = i;
                        else
                            j = j;                        
                        }
               else
                        j = j;                




            21. main()
{
                        float i=1.5;
            switch(i)
                        {
                        case 1: printf("1");
                                    case 2: printf("2");
                                    default : printf("0");
            }
}


21. Answer:
Compiler Error: switch expression not integral
Explanation:
                        Switch statements can be applied only to integral types.


22. Which version do you prefer of the following two,
1) printf(“%s”,str);      // or the more curt one
2) printf(str);


22. Answer & Explanation:
Prefer the first one. If the str contains any  format characters like %d then it will result in a subtle bug.



23. void main()
{
char ch;
for(ch=0;ch<=127;ch++)
printf(“%c   %d \n“, ch, ch);
}

23. Answer: Infinite Loop
            Implementaion dependent
Explanation:
The char type may be signed or unsigned by default. If it is signed then ch++ is executed after ch reaches 127 and rotates back to -128. Thus ch is always smaller than 127.




24. main()
{
char a[4]="HELLO";
printf("%s",a);
}         


24. Answer:
                        Compiler error: Too many initializers
Explanation:
The array a is of size 4 but the string constant requires 6 bytes to get stored.


25.       main()
{         
char a[4]="HELL";
printf("%s",a);
}

25. Answer:
                        HELL
Explanation:
The character array has the memory just enough to hold the string “HELL” and doesnt have enough space to store the terminating null character. So it prints the HELL correctly and continues to print garbage values till it    accidentally comes across a NULL character.

Session -2

26.  main()
{
            int c=- -2;
            printf("c=%d",c);
}

26. 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.



27. void main()
{
            int i;
            char a[]="\0";
            if(printf("%s\n",a))
                        printf("Ok here \n");
            else
                        printf("Forget it\n");
}


27. Answer:
 Ok here
Explanation:
Printf will return how many characters does it print. Hence printing a null character returns 1 which makes the if statement true, thus "Ok here" is printed.





28. What is the output of the program given below

main()
    {
       signed char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
    }
28. Answer
                        -128
Explanation
Notice the semicolon at the end of the for loop. THe initial value of the i is set to 0. The inner loop executes to increment the value from 0 to 127 (the positive range of char) and then it rotates to the negative value of -128. The condition in the for loop fails and so comes out of the for loop. It prints the current value of i that is -128.




29. main()
            {
       char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
       
 }

29. Answer:
                        Behavior is implementation dependent.
Explanation:
The detail if the char is signed/unsigned by default is implementation dependent. If the implementation treats the char to be signed by default the program will print –128 and terminate. On the other hand if it considers char to be unsigned by default, it goes to infinite loop.
Rule:
You can write programs that have implementation dependent behavior. But dont write programs that depend on such behavior.



30. main()
{
int i = 3;
for (;i++=0;) printf(“%d”,i);
}


30. Answer:
                        Compiler Error: Lvalue required.
Explanation:
As we know that increment operators return rvalues and  hence it cannot appear on the left hand side of an assignment operation.


31. main()
{
                        int i=5,j=10;
            i=i&=j&&10;
                        printf("%d %d",i,j);
}

31. Answer:
1 10
Explanation:
The expression can be written as i=(i&=(j&&10)); The inner expression (j&&10) evaluates to 1 because j==10. i is 5. i = 5&1 is 1. Hence the result.



Session – 3

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

32. 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.



33. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}


33. 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.




34. main()
{
              int i=5,j=6,z;
              printf("%d",i+++j);
             }

34. Answer:
11
Explanation:
the expression i+++j is treated as (i++ + j)   




35. main()
{
 int i =0;j=0;
 if(i && j++)
            printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}

35. Answer:
0..0
Explanation:
The value of i is 0. Since this information is enough to determine the truth value of the boolean expression. So the statement following the if statement is not executed.  The values of i and j remain unchanged and get printed.


36. void main()
{
            unsigned giveit=-1;
            int gotit;
            printf("%u ",++giveit);
            printf("%u \n",gotit=--giveit);
}
36. Answer:
 0 65535



37. main()
{
            unsigned int i=10;
            while(i-->=0)
                        printf("%u ",i);

}

37. Answer:
            10 9 8 7 6 5 4 3 2 1 0 65535 65534…..
Explanation:
Since i is an unsigned integer it can never become negative. So the expression i-- >=0  will always be true, leading to an infinite loop.         



38. main()
{
            unsigned int i=65000;
            while(i++!=0) ;
            printf("%d",i);
}


38.  Answer:
 1
Explanation:
Note the semicolon after the while statement. When the value of i becomes 0 it comes out of while loop. Due to post-increment on i the value of i while printing is 1.



39. main()
{
int i=5;
printf(“%d”,i=++i ==6);
}

39. Answer:
1
Explanation:
The expression can be treated as i = (++i==6), because == is of higher precedence than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result.


40.  main()
{
                        int i=4,j=7;
            j = j || i++ && printf("YOU CAN");
                        printf("%d %d", i, j);
}

40. Answer:
4 1
Explanation:
The boolean expression needs to be evaluated only till the truth value of the expression is not known. j is not equal to zero itself means that the expression’s truth value is 1. Because it is followed by || and true || (anything) => true where (anything) will not be evaluated. So the remaining expression is not evaluated and so the value of i remains the same.
Similarly when && operator is involved in an expression, when any of the operands become false, the whole expression’s truth value becomes false and hence the remaining expression will not be evaluated.    
            false && (anything) => false where (anything) will not be evaluated.



                                                              SESSION 1

1. main()
{
            float me = 1.1;
            double you = 1.1;
            if(me==you)
printf("Hello");
else
                        printf("Welcome");
}

Ans: welcome

2. main()
{
            extern int i;
            i=20;
printf("%d",i);
}

Ans: linker error.

3. main()
{
            int i=3;
            switch(i)
             {
                default:printf("zero");
                case 1: printf("one");
                           break;
               case 2:printf("two");
                          break;
              case 3: printf("three");
                          break;
              } 
}

Ans: Three
4. main()
{
            char string[]="Hello World";
            display(string);
}
void display(char *string)
{
            printf("%s",string);
}                   
Ans::Hello World
         

5. #define int char
main()
{
            int i=65;
            printf("sizeof(i)=%d",sizeof(i));
}

Ans: 1

6. main()
{
int i=10;
i=!i>14;
printf ("i=%d",i);
}

Ans: 0


7. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
Ans: 64


8. #include <stdio.h>
#define a 10
main()
{
#define a 50
printf("%d",a);
}

Ans: 50

9. #define clrscr() 100
main()
{
clrscr();
printf("%d\n",clrscr());
}

Ans: 100

10.main()
{
printf("%p",main);
}

Ans : address of main

11. main()
{
clrscr();
}
clrscr();
ans::error:type mismatch

12. main()
{
 int i=400,j=300;
 printf("%d..%d");
}
Ans::300 400

13. main()
{
    int i=1;
    while (i<=5)
    {
       printf("%d",i);
       if (i>2)
              goto here;
       i++;
    }
}
fun()
{
   here:
     printf("PP");
}

Ans: error::goto here sud be defined and called in same fuction

14. #include<stdio.h>
main()
{
int i=1,j=2;
switch(i)
 {
 case 1:  printf("GOOD");
                break;
 case j:  printf("BAD");
               break;
 }
}

Ans: Error::case sud have a constant value

15. main()
{
int i;
printf("%d",scanf("%d",&i));  // value 10 is given as input here
}


Ans: 1

16. main()
     {
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
      }


Ans: 1 ya since i++ will not increment first time so I is o in for that’s why

17 . main()
{
 extern int i;
 i=20;
 printf("%d",sizeof(i));
}

Ans: Linker error


18. main()
{
 extern out;
 printf("%d", out);
}
 int out=100;

Ans: 100

19.       main()
{
 show();
}
void show()
{
 printf("I'm the greatest");
}
            Ans::I m the greatest

20. main()
            {
            int i=-1;
            +i;
            printf("i = %d, +i = %d \n",i,+i);
            }

Ans: -1 -1

21. What are the files which are automatically opened when a C file is executed?

Ans: stdinput,stdoutput,stderror.

22. main()
            {
            main();
            }

Ans: runs until stack overflow.


23. main()
            {
            char not;
            not=!2;
            printf("%d",not);
            }

Ans: 0 if %c is used then a blank is printed as !2=0

24. #define FALSE -1
            #define TRUE   1
            #define NULL   0
            main() {
               if(NULL)
                        puts("NULL");
               else if(FALSE)
                        puts("TRUE");
               else
                        puts("FALSE");
               }

Ans: TRUE ::print as it anythng in double quotes
25. main()
            {
            int k=1;
            printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
            }

Ans:  1==1 is True.

26. main()
            {
            int y;
            scanf("%d",&y); // input given is 2000
            if( (y%4==0 && y%100 != 0) || y%100 == 0 )
                 printf("%d is a leap year",y);
            else
                 printf("%d is not a leap year",y);
            }

Ans: 2000 leap year

27. main()
            {
            int i=-1;
            -i;
            printf("i = %d, -i = %d \n",i,-i);
            }

Ans: i=-1 i=1




28. main()
{
 char c=' ',x,convert(z);
 getc(c);
 if((c>='a') && (c<='z'))
 x=convert(c);
 printf("%c",x);
}

convert(z)
{
  return z-32;
}

Ans: Error//1ST convert (char);will do in fuction prtotype+fuc dec convert(char  z) sud be used+getc() is not a library function


29. main(int argc, char **argv)
{
            printf("enter the character");
            getchar();
            sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
 return num1+num2;
}

Ans:Error??

30. int i;
            main(){
int t;
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
                        printf("%d--",t--);
                        }
            // If the inputs are 0,1,2,3 find the o/p

Ans: 4—0
        3—1
        2—2 //GUD 1
           
         
31. main(){
  int a= 0;int b = 20;char x =1;char y =10;
  if(a,b,x,y)
        printf("hello");
 }
Ans:hello

32. main()
{
 unsigned int i;
            for(i=1;i>-2;i--)
                                    printf("c aptitude");
}

Ans: infinite.

33. void main()
{
            while(1)
{
                        if(printf("%d",printf("%d")))
                                    break;
                        else
                                    continue;
            }
}

Ans: (garbage or 0)  1(compiler dependent)

34. #include<conio.h>
main()
{
            int x,y=2,z,a;
            if(x=y%2)
 z=2;
                        a=2;
            printf("%d %d ",z,x);
}

Ans: garbage  0

35. main()
    {
       unsigned char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
    }

Ans: infinite
36. main()
            {
       char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
       
 }
Ans: -128


39. main()
{
                        char p[ ]="%d\n";
p[1] = 'c';
printf(p,65);
}

Ans: A

40. main()
{
while (strcmp(“some”,”some\0”))
printf(“Strings are not equal\n”);
            }

Ans: no output//strcmp(gives 0 if all letters are equal)

41. main()
{
char str1[] = {‘s’,’o’,’m’,’e’};
char str2[] = {‘s’,’o’,’m’,’e’,’\0’};
while (strcmp(str1,str2))
printf(“Strings are not equal\n”);
}

Ans: no output.

42. main()
{
                        int i=10,j=20;
            j = i, j?(i,j)?i:j:j;
                        printf("%d %d",i,j);
}

Ans: 10 10

43. main()
{
                        register int a=2;
            printf("Address of a = %d",&a);
                        printf("Value of a   = %d",a);
}

Ans: error

            44. main()
{
                        float i=1.5;
            switch(i)
                        {
                        case 1: printf("1");
                                    case 2: printf("2");
                                    default : printf("0");
            }
}

Ans: error


45. main()
{         
                        extern i;
            printf("%d\n",i);
                        {
                                    int i=20;
                        printf("%d\n",i);
                        }
   }

Ans: linker error(run time error)


46. char inputString[100] = {0};
To get string input from the keyboard which one of the following is better?
            1) gets(inputString)
            2) fgets(inputString, sizeof(inputString), fp)

Ans: 1.


47. Which version do you prefer of the following two,
1) printf(“%s”,str);      // or the more curt one
2) printf(str);


Ans: 1
48. void main()
{
char ch;
for(ch=0;ch<=127;ch++)
printf(“%c   %d \n“, ch, ch);
}

Ans: infinite

49. main()
{
char a[4]="HELLO";
printf("%s",a);
}         

Ans: error//too many intializers

50.       main()
{         
char a[4]="HELL";
printf("%s",a);
}

Ans: HELLgarbage

51. main()
{
printf("%d", out);
}
int out=100;

Ans: error








SESSION 2

1. 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]);
}

Ans: mmmm
       aaaa
       nnnn

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

Ans: 1 2


*3. main()
{
              printf("%x",-1<<4);
}

Ans: 0xfff0

4.  main()
{
            int c=- -2;
            printf("c=%d",c);
}

Ans: 2

5.. main()
{
 char *p;
 p="Hello";
 printf("%c\n",*&*p);
}
//here*&p==&*p
Ans: H

6. main()
            {
            char *str1="abcd";
            char str2[]="abcd";
            printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd"));
            }

Ans: 2 5 5

7. #include<stdio.h>
main()
  {
    register i=5;//valid int can be dropped
    char j[]= "hello";                    
     printf("%s  %d",j,i);
}

Ans: hello 5


8. void main()
{
            int i;
            char a[]="\0";
            if(printf("%s\n",a))
                        printf("Ok here \n");
            else
                        printf("Forget it\n");
}

Ans: Ok here


9. What is the output of the program given below

main()
    {
       signed char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
    }

Ans : -128

10. main()
            {
       char i=0;
       for(;i>=0;i++) ;
       printf("%d\n",i);
       
 }

Ans : -128


*11. void main()
         {
if(~0 == (unsigned int)-1)
printf(“You can answer this if you know how values are represented in memory”);
         }

           Ans : you can answer this if you know how values are represented in memory


12. main()
{
int i = 3;
for (;i++=0;) printf(“%d”,i);
}

Ans : L value required error.
13. main()
{
                        int i=5,j=10;
            i=i&=j&&10;
                        printf("%d %d",i,j);
}
Ans : 1 10

14. #define DIM( array, type) sizeof(array)/sizeof(type)
main()
{
int arr[10];
printf(“The dimension of the array is %d”, DIM(arr, int));   
}

Ans: 10


15.       int DIM(int array[])
{
return sizeof(array)/sizeof(int );
}
main()
{
int arr[10];
printf(“The dimension of the array is %d”, DIM(arr));   
}

Ans: The  dimension of the array is 10

16. #define max 5
            #define int arr1[max]
            main()
            {
            typedef char arr2[max];
            arr1 list={0,1,2,3,4};
            arr2 name="name";
            printf("%d %s",list[0],name);
            }
Ans: Error


SESSION 3
1.
 main()
            {
            static int var = 5;
            printf("%d ",var--);
            if(var)
                        main();
            }

Ans : 5 4 3 2 1

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

Ans: 0 0 1 3 1


3. #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);//asc of ‘\n’==10 so 11+98-32==77//
}

Ans: 77

4. main()
{
int i=5;
printf("%d%d%d%d%d",i++,i--,++i,--i,i);
}

Ans : 4,5,5,4,5



5. main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0')
++*p++;//whever there is a pointer we consider r to l so 1st post           increment
printf("%s   %s",p,p1);
}

Ans:  ibj!gsjfoet


6.  main()
{
   static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
    int i;
    char *t;
    t=names[3];
    names[3]=names[4];
    names[4]=t;
    for (i=0;i<=4;i++)
            printf("%s",names[i]);
}

Ans: Error

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

Ans: 12

8.         void main()
{
            int i=5;
            printf("%d",i++  +++i);
}

Ans : Lvalue required error

9. #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);
}
Ans : 77

10. #include<stdio.h>
main()
 {
   const int i=4;
   float j;
   j = ++i;
   printf("%d  %f", i,++j);
 }

Ans: error

11. main()
{
              int i=5,j=6,z;
              printf("%d",i+ + +j);
             }

Ans: 11

12. main()
{
 int i=_l_abc(10);
             printf("%d\n",--i);
}
int _l_abc(int i)
{
 return(i++);
}

Ans : 9.

13. main()
{
 int i =0;j=0;
 if(i && j++)
            printf("%d..%d",i++,j);
printf("%d..%d,i,j);
}

Ans: 0 0
     
*14. main()
{
char *p;
p="%d\n";
           p++;
           p++;
           printf(p-2,300);
}
//printf(name of string )==will print string..
Ans: 300

15. void main()
{
            static int i=5;
            if(--i){
                        main();
                        printf("%d ",i);
            }
}
Ans: 0 0 0 0


16. void main()
{
            int k=ret(sizeof(float));
            printf("\n here value is %d",++k);
}
int ret(int ret)
{
            ret += 2.5;
            return(ret);
}

Ans: 7.

17. void main()
{
            char a[]="12345\0";
            int i=strlen(a);
            printf("%d\n",++i);
}
Ans: 6

*18. void main()
{
            unsigned giveit=-1;
            int gotit;
            printf("%u ",++giveit);
            printf("%u \n",gotit=--giveit);
}

Ans: 0 65535

19.  void main()
{
            int i=i++,j=j++,k=k++;
printf(“%d%d%d”,i,j,k);
}
Ans: garbage

20. void main()
{
            static int i=i++, j=j++, k=k++;
printf(“i = %d j = %d k = %d”, i, j, k);
}
Ans:  Error

21. main()
{
            unsigned int i=10;
            while(i-->=0)
                        printf("%u ",i);

}

Ans: infinite


22. main()
{
            unsigned int i=65000;
            while(i++!=0);
            printf("%d",i);
}
Ans: 1

23. main()
{
            int i=0;
            while(+(+i--)!=0)
                        i-=i++;
            printf("%d",i);
}
Ans: -1//ya check while

24. main()
{
            float f=5,g=10;
            enum{i=10,j=20,k=50};
            printf("%d\n",++k);//cannot increment.
            printf("%f\n",f<<2);//illegal instruction
            printf("%lf\n",f%g);//illegal instruction
            printf("%lf\n",fmod(f,g)); //Legal instruction
}
Ans: error

25.. main()
            {
             int i=5;
             printf("%d",++i++);
}

Ans: l value required ++(i++) since (i++)will give an constatnt value and cant perform ++ on a constant value error

26. main()
{
int i=5;
printf(“%d”,i=++i ==6);
}

Ans: 1

27.  void main()
{
static int i;
while(i<=10)
(i>2)?i++:i--;
            printf(“%d”, i);
}

Ans: 32767//ya

28.  main()
{
                        int i=4,j=7;
            j = j || i++ && printf("YOU CAN");
                        printf("%d %d", i, j);
}
Ans:  4 1

29.       char *someFun1()
            {
            char temp[ ] = “string";
            return temp;
            }
            char *someFun2()
            {
            char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};
            return temp;
            }
            int main()
            {
            puts(someFun1());
            puts(someFun2());
            }

Ans: garbage


SESSION 4
1.         main()
{
                        int a=10,*j;
            void *k;
                        j=k=&a;
            j++; 
                        k++;
            printf("\n %u %u ",j,k);
}

Ans: type of k is unknown hence ERROR

2.         Is this code legal?
int *ptr;
ptr = (int *) 0x400;
       Ans:  Legal

3.         void main()
{
int i=10, j=2;
int *ip= &i, *jp = &j;
int k = *ip/*jp;//ya but *ip/(*jp) is valid since /* is used for    comment
printf(“%d”,k);
}         

Ans : error

4. void main()
{
printf(“sizeof (void *) = %d \n“, sizeof( void *));
            printf(“sizeof (int *)    = %d \n”, sizeof(int *));
            printf(“sizeof (double *)  = %d \n”, sizeof(double *));
            printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct unknown *));
            }

Ans: 2 2 2 2

5. void main()
{
int *i = 0x400;  // i points to the address 400
*i = 0;              // set the value of memory location pointed by i;
}

Ans : Legal

6. What is the subtle error in the following code segment?
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++<n)
                        p = &arr[i];
*p = 0;
}

Ans: only one stmt executes with in while loop.

7. #include <stdio.h>
main()
{
char * str = "hello";
char * ptr = str;
char least = 127;
while (*ptr++)
                  least = (*ptr<least ) ?*ptr :least;
printf("%d",least);
}
Ans: 0//gud 1

8. main()
{
                        int i=300;
            char *ptr = &i;
                        *++ptr=2;
            printf("%d",i);
}

Ans:300

*9. main()
{
                        int i = 258;
            int *iPtr = &i;
                        printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}         
         //
Ans: 2 1

*10. main()
{
                        int i = 257;//
            int *iPtr = &i;
                        printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) );
}

Ans: 1 1

11. main()
{
            static int a[3][3]={1,2,3,4,5,6,7,8,9};
            int i,j;
            static *p[]={a,a+1,a+2};
                        for(i=0;i<3;i++)
            {
                                    for(j=0;j<3;j++)
                                    printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j),
                                    *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));
                        }
}

Ans :   1 1 1  1
              2 4 2 4
              3 7 3 7
        
            4 2 4 2
              5 5 5 5
           6 8 6 8
        
           7 3 7 3
           8 6 8 6
           9 9 9 9
//gud que
12. main()
{
                        char *p="GOOD";
            char a[ ]="GOOD";
printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d",      sizeof(p), sizeof(*p), strlen(p));
            printf("\n sizeof(a) = %d, strlen(a) = %d", sizeof(a), strlen(a));
}

Ans: 2 1 4
        5 4
13. main()
{
                        int a=2,*f1,*f2;//a=2,f1=&a,f2=&a//
                 f1=f2=&a;
                        *f2+=*f2+=a+=2.5;
            printf("\n%d %d %d",a,*f1,*f2);
}

Ans: 16 16 16
Gud1
            14.
 1. const char *a;
2. char* const a;
3. char const *a;
-Differentiate the above declarations.

Ans: data constant
Pointer constant
Data constant

15.       main()
{
char *p = “ayqm”;
char c;
c = ++*p++;
printf(“%c”,c);
}
Ans:b

16. main()
{         
char *p = “ayqm”;
printf(“%c”,++*(p++));
}

Ans: b

17. What is the output for the following program

            main()
                            {
      int arr2D[3][3];
       printf("%d\n", ((arr2D==* arr2D)&&(* arr2D == arr2D[0])) );
               }
Ans: 1


18. Is the following statement a declaration/definition. Find what does it mean?
int (*x)[10];
Ans:  pointer to an array of 10 integer data.

19. main()
{
            int a[10];
            printf("%d",*a+1-*a+3);
}
Ans: 4
Gud1
20. void main()
{
            void *v;
            int integer=2;
            int *i=&integer;
            v=i;
            printf("%d",(int*)*v);
}

Ans : 2

21. # include <stdio.h>
int one_d[]={1,2,3};
main()
{
 int *ptr;
 ptr=one_d;
 ptr+=3;
 printf("%d",*ptr);
}
//if ptr+=2 then 3 will printed
Ans: garbage

22. main()
{
 char *p;
 int *q;
 long *r;
 p=q=r=0;
 p++;
 q++;
 r++;
 printf("%p...%p...%p",p,q,r);
}

Ans : 1 2 4

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

Ans: 10 garbage

24. main()
            {
                int *j;
                {
                 int i=10;
                 j=&i;
                 }
                 printf("%d",*j);
}
Ans: 10

25. main()
            {
            char *cptr,c;
            void *vptr,v;
            c=10;  v=0;
            cptr=&c; vptr=&v;
            printf("%c%v",c,v);
            }

Ans: error

26. main()
{
 int  i, n;
 char *x = “girl”;
 n = strlen(x);
 *x = x[n];
 for(i=0; i<n; ++i)
   {
printf(“%s\n”,x);
x++;
   }
 }

Ans: irl
            rl
             l


27. main ( )
{
 static char *s[ ]  = {“black”, “white”, “yellow”, “violet”};
 char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
 p = ptr;
 **++p;
 printf(“%s”,*--*++p + 3);
}

Ans::ck
28. main( )
{
 void *vp;
 char ch = ‘g’, *cp = “goofy”;
 int j = 20;
 vp = &ch;
 printf(“%c”, *(char *)vp);//g
 vp = &j;
 printf(“%d”,*(int *)vp);//20
 vp = cp;
 printf(“%s”,(char *)vp + 3);//fy
Ans: g 20 fy


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

Ans: Error (Null pointer assignment)

30. main( )
{
 static int  a[ ]   = {0,1,2,3,4};
 int  *p[ ] = {a,a+1,a+2,a+3,a+4};
 int  **ptr =  p;
 ptr++;
 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
 *ptr++;
 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
 *++ptr;
 printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);
 ++*ptr;
       printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);


31. main( )
{
  int a[ ] = {10,20,30,40,50},j,*p;
  for(j=0; j<5; j++)
    {
printf(“%d” ,*a);
a++;
    }
    p = a;
   for(j=0; j<5; j++)
      {
printf(“%d ” ,*p);
p++;
      }
 }

Ans: Error

32. main( )
{
  int a[2][3][2] = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};
  printf(“%u %u %u %d \n”,a,*a,**a,***a);
        printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);
       }

Ans:  let base address be 1000.

1000 1000 1000 2
          1012 1004 1002 3


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

Ans: garbage garbage

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

Ans: 2 2 2 2 2
        2 3 4 6 5


35. void main()
{
            int  const * p=5;
            printf("%d",++(*p));
}

Ans:  error


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

Ans: bye.

2. In the following pgm add a  stmt in the function  fun such that the address of
'a' gets stored in 'j'.
main(){
  int * j;
  void fun(int **);
  fun(&j);
 }
 void fun(int **k) {
  int a =0;
  /* add a stmt here*/
 }

Ans: *k=&a;

3.         main(){
 char a[100];
 a[0]='a';a[1]='b';a[2]='c';a[4]='d';
 abc(a);
}
abc(char a[]){
 a++;
             printf("%c",*a);
 a++;
 printf("%c",*a);
}

Ans: b c

4.         func(a,b)
int a,b;
{
 return( a= (a==b) );
}

main()
{
int process(),func();
printf("The value of process is %d !\n ",process(func,3,6));
}

process(pf,val1,val2)
int (*pf) ();
int val1,val2;
{
return((*pf) (val1,val2));
 }

Ans: error


5.         #define prod(a,b) a*b
main()
{
            int x=3,y=4;
            printf("%d",prod(x+2,y-1));
}

Ans: 10

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

Ans:  20 10


8. Explain the statement:       
void ( * abc( int, void ( *def) () ) ) ();





10. Declare an array of N pointers to functions returning pointers to functions returning pointers to characters?


11. Is there any difference between the two declarations,
int foo(int *arr[]) and
int foo(int *arr[2])


12. char *someFun()
            {
            char *temp = “string constant";
            return temp;
            }
           
int main()
            {
            puts(someFun());
            }

Ans: string constant.

13. main()
 {
 int i=_l_abc(10);
printf(”%d\n”,–i);
 }

 int _l_abc(int i)
{
return(i++);
}

Ans: -10
14. main()
{
 char a[100];
a[0]=’a';
a[1]]=’b';a[2]=’c';a[4]=’d'; abc(a);
}

 abc(char a[])
{
 a++;
 printf(”%c”,*a);
 a++;
printf(”%c”,*a);
 }

15. void main()
 {
 static int i=5;
 if(–i)
{
main();
 printf(”%d “,i);
}
}

Ans:Infinite Loop No Output


SESSION 6
1.  what will be the position of the file marker?
            a: fseek(ptr,0,SEEK_SET);
            b: fseek(ptr,0,SEEK_CUR);

Ans:  0 offset

2.         What is the problem with the following code segment?
            while ((fgets(receiving array,50,file_ptr)) != EOF)
                                    ;
Ans : while((fgets(receiving array,50,file_ptr))!=NULL).

3. #include<stdio.h>
main()
{
FILE *ptr;
char i;
ptr=fopen("zzz.c","r");
while((i=fgetch(ptr))!=EOF)
printf("%c",i);
}

Ans: linker error.fgetch() no such built in function.

4. void main()
{
int *mptr, *cptr;
mptr = (int*)malloc(sizeof(int));
printf(“%d”,*mptr);
cptr = (int*)calloc(sizeof(int),1);
printf(“%d”,*cptr);
}

Ans: garbage 0

5. The value of EOF is -1.

  1. Using pointers to call a function is called as function pointer


  1. The variable that contains address of another variable is called as        Pointer

8. How many values can be returned by a C++ function?
            Ans: one

9. Which of the following is mandatory for all C++ program?

 a) main()
b) scanf()
c) system()
d) all the above
Ans : main()

10. The variables that can be used only within the function in which it is declared is called as Local variable.





SESSION 7

1. #include<stdio.h>
main()
{
struct xx
{
      int x=3;
      char name[]="hello";
 };
struct xx *s;
printf("%d",s->x);
printf("%s",s->name);
}

Ans: error//declare a data type of structure then add sud be given to struct pointer

*2. #include<stdio.h>
main()
{
struct xx
{
int x;
struct yy
{
char s;
            struct xx *p;
};
struct yy *q;
};
}
Ans: Error


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

Ans: 0 1 2


6.         struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};

main()
{
 struct aaa abc,def,ghi,jkl;

 int x=100;

 abc.i=0;abc.prev=&jkl;
 abc.next=&def;

 def.i=1;def.prev=&abc;
def.next=&ghi;
 ghi.i=2;ghi.prev=&def;
 ghi.next=&jkl;
 jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
 x=abc.next->next->prev->next->i;

 printf("%d",x);
}
Ans : 2


*7.       struct point
 {
 int x;
 int y;
 };
struct point origin,*pp;
main()
{
pp=&origin;
printf("origin is(%d%d)\n",(*pp).x,(*pp).y);
printf("origin is (%d%d)\n",pp->x,pp->y);
}
           
Ans: 0 0
        0 0
                       
8. What is the output for the program given below

     typedef enum errorType{warning, error, exception,}error;
     main()
    {
        error g1;
        g1=1;
        printf("%d",g1);
     }
  Ans: Error (multiple declaration of error).

9.              typedef struct error{int warning, error, exception;}error;
     main()
    {
        error g1;
        g1.error =1;
        printf("%d",g1.error);
     }
Ans : error
 
10. 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);
}

Ans: error


11. main()
{
struct date;
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);
}
Ans: error


12.       There were 10 records stored in “somefile.dat” but the following program printed 11 names. What went wrong?
void main()
{
struct student
{         
char name[30], rollno[6];
}stud;
FILE *fp = fopen(“somefile.dat”,”r”);
while(!feof(fp))
 {
                        fread(&stud, sizeof(stud), 1 , fp);
puts(stud.name);
}
}

Ans: last record will get printed twice when feof is used.


13.       Is the following code legal?
struct a
    {
int x;
 struct a b;
    }

Ans : no

14.       Is the following code legal?
struct a
    {
int x;
            struct a *b;
    }

Ans: no//

15.       Is the following code legal?
typedef struct a
    {
int x;
 aType *b;
    }aType

Ans: syntax error.
16.       Is the following code legal?
typedef struct a aType;
struct a
{
int x;
aType *b;
};

Ans: yes


17.       Is the following code legal?
void main()
{
typedef struct a aType;
aType someVariable;
struct a
{
int x;
      aType *b;
              };
}
Ans: no

18.       Printf can be implemented by using  __________ list.

19. main()
 {
float f=5,g=10;
 enum{i=10,j=20,k=50};
 printf(”%d\n”,++k);
 printf(”%f\n”,f<<2);
printf(”%lf\n”,f%g);
printf(”%lf\n”,fmod(f,g));
 }

 Ans:error.





1)         struct value
            {
                        int bit1:1;
                        int bit3:4;
                        int bit4:4;
            }bit={1,2,2};
            printf("\n %d %d %d",bit.bit1,bit.bit3,bit.bit4);

ans::-1,2,2


2)         enum value{VAL1=0,VAL2,VAL3,VAL4,VAL5}var;
            printf("%d",sizeof(var));
ans::2

3)         enum days{MON=-1,TUE,WED=55,THU,FRI,SAT};
            printf("%d %d %d %d %d %d",MON,TUE,WED,THU,FRI,SAT);
ans::-1,0,55,56,57,58


4)         void main()
            {
                        union var
                        {
                                    int a,b;
                         };
                         union var v;
                         v.a=80;
                         v.b=100;
                        printf("%d",v.a);
             }

ans::100
5)         void main()
            {
                        struct node
                        {
                                    int data;
                                    struct node *link;
                         };
                        struct node *p,*q;
                        p=(struct node *)malloc(sizeof(struct node));
                        q=(struct node *)malloc(sizeof(struct node));
      printf("%d %d",sizeof(p),sizeof(q));

            }
ans::2,2



6)         struct byte
            {
                        int one:1;
            };
            struct byte var={1};
            printf("%d",var.one);

ans::-1


7)         enum status{pass,fail,atkt};
            enum status stud1,stud2,stud3;
            stud1=pass;
            stud2=atkt;
            stud3=fail;
            printf("\n %d %d %d",stud1,stud2,stud3);

ans::0 1 2


8)         int i=4,j=8;
   printf("%d %d %d ",i|j&j|i,i|j&&j|i,i^j);




9)                     union x
            {
                        int i;
                        char ch[2];
             };
             union x u;
             u.ch[0]=3;
             u.ch[1]=2;
    printf("%d %d %d ",u.ch[0],u.ch[1],u.i);



10)       struct course
            {
                        int courseno;
                        char coursename[25];
             };
void main()
{
            struct course c[]={
                        {102,"Thermal"},{103,"Manufacturing"},{104,"Design"}
                                     };
            printf("%d",c[1].courseno);
   printf("%s",(*(c+2)).coursename);
}
           
ans::103 Design



11)       void main()
{
            union test
            {
                        int i;
                        float f;
                        char c;
            };
            union test *t;
            t=(union test *)malloc(sizeof(union test));
            t->i=10;
            printf("%d\n",t->c);
            t->f=10.10f;
            printf("%f\n",t->f);
            t->c='a';
            printf("%c\n",t->i);
            }




12)       void main()
{
            struct address
            {
            char phone[15];
            char city[25];
            int pin;
             };
             struct emp
             {
                        char name[25];
                        struct address a;
             };
             struct emp e={"jeru","2344","kerala",55};
             printf("\n name=%s phone=%s",e.name,e.a.phone);
             printf("\n city=%s pin=%d",e.a.city,e.a.pin);
}
ans:: name=jeru  phone=2344 city=kerala  pin=55



13)       struct book
{
            char name[25];
            char author[25];
            int no;
};
void display(struct book *);
void main()
{
            struct book b1={"Let us C","YPK",101};
            display(&b1);
}
void display(struct book *b)
{
            printf("\n %s %s %d",b->name,b->author,b->no);
}

ans:: Let us C,YPK,101


14)       void main()
{
            struct sample
            {
                        int num;
                        char m1[50];
                        char m2[50];
            }m;
            m.num=1;
            strcpy(m.m1,"i love India");
            strcpy(m.m2,"We are Indians");
            printf("\n %u %u %u",&m.num,m.m1,m.m2);
}

ans::garbage value will be printed


16)       void main()
{
            struct sample
            {
                        int a:3;
                        int b:2;
                        unsigned int c:3;
            };
            struct sample s;
            s.a=-2;
            s.b=1;
            s.c=3;
            printf("\nThe value of a is %d",s.a);
            printf("\nThe value of b is %d",s.b);
            printf("\nThe value of c is %d",s.c);

            s.a=2;
            s.b=0;
            s.c=5;
            printf("\nThe value of a is %d",s.a);
            printf("\nThe value of b is %d",s.b);
            printf("\nThe value of c is %d",s.c);

            printf("\n Total size of the structure sample is %d",sizeof(s));
}






17)                   struct sample
            {
                        char name[10];
                        int no;
             };
             void main()
             {
                        struct sample s;
                        void passrecord(struct sample);
                        printf("\n Enter the name:");
                        scanf("%s",s.name);
                        printf("\n Enter the Roll Number:");
                        scanf("%d",s.no);
                        passrecord(s);
                        printf("\n values after the function:\n");
                        printf("\n Name           :           %s",s.name);
                        printf("\n No               :           %d",s.no);
             }
             void passrecord(struct sample x)
             {
                        x.no=x.no+10;
                        printf("\n Inside the function:\n");
                        printf("\n Name           :           %s",x.name);
                        printf("\n No               :           %s",x.no);
   }






18) Point out if there is any error in the program
            void main()
            {
            struct employee
            {
                        char name[25];
                        int age;
                        float bs;
             };
             struct employee e;
             strcpy(e.name,"Hacker");
             age=25;
             printf("\n %s %d",e.name,e.age);
            }

ans::error



1.         can we have more than one data members in a doubly linked
list structure

a)         yes
b)         no


3.         Arrange the code below, to delete a node being pointer
by temp.
a)         free(temp)
b)         temp->prev->next=temp->next
c)         temp->next->prev=temp->prev;

a) b c a   
b) c b a
c) a b c
d) both a and b

4.
struct list
{
int data;
struct list* left,
struct list* right;
};

what are the steps required to insert a new node n at a
point pointed by ptr?
note: ptr is not the last node.

1.         n->left = ptr->left
2.         n->left->right = n
3.         ptr->left = n
4.         n->right = ptr

a)1 2 3 4          b) 4 3 2 1         c) 4 2 1 3         d) 3 1 2 4
.


5.         where does the pointer temp pointing after the

code execution, where head is startning node in D.L.L of nine nodes,.
 for( i=1; head!=NULL;head=head ->next, i++)
{
            If(i==1)
                                    temp=head;
                        else if (i%2==1)
                                    temp= temp->next;
            }

a)         middle node
b)         last but one node
c)         cannot make out
d)         second node
6. What does function do, if temp is pointing to a node in DLL and

temp1 is a newnode?
temp1 -> prev = temp
temp1 -> next =temp ->next
temp -> next->prev = temp1
temp -> next = temp1


a)         inserts node before temp;
b)         inserts after temp
c)         deletes node pointed by temp;
d)         none of the above
7. 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

8. What does the code below do, where head is starting node &
temp is temporary pointer
temp=head;
            head= head -> next;
            head -> prev = null;
            free(temp);

a)         no effect
b)         NULL data is stored
c)         Starting node is deleted
d)         First and second node are shuffled

9. what does the code below do, where head is pointing to first

node & temp is a temporary pointer. 10 be the number of nodes
            temp = head;
while (temp->next->next!=NULL)
{
            Temp = temp ->next;
}
temp -> prev -> next = temp -> next;
temp -> next -> prev = temp -> prev;
free(temp);

a)         no effect
b)         deletes some node
c)         deletes 2nd last node
d)         deletes last node
10. what does the code do, if there are 100 nodes

temp=head;
while ( temp -> next -> next -> next != NULL)
{
            Temp = temp -> next;
}
temp -> prev -> next = temp -> next;
temp -> next -> prev = temp -> prev;
free ( temp );

a)         deletes 3rd last node
b)         no effect
c)         3rd node is deleted
d)         Middle node is deleted

1.main()
{
    printf("%c\n", '1' + 1);
}

a)ASCII value of '1' is required to find out the answer
b)2
c)50
d)Syntax Error
ans::b
2. main()
{
    char y[10] = "abcdefghi";
    char *p = y;
    p = p + 9;
    printf("%c\n",*p);
}

a)i
b)Program will have runtime error
c)Unpredictable
d)No visible output
ans::d
3. main()
{
    int y[2][2] = { {1,2}, {3,4} };
    int *p = &y[1];
    p = p + 1;
    printf("%d\n",*p);
}

a)4
b)3
c)The program doesn't compile
d)Output is unpredicatable
ans::a











4. int y = 10;
main()
{
    int x = 10;
    int y = 20;
    x = x + y;
    if (x >= 30)
    {
        int y = 30;
        x = x + y;
    }
    else
    {
        int y = 40;
        x = x + y;
    }
    printf("%d\n", x);
}
a)40
b)50
c)60
d)70
ans::b

5. main()
{
    unsigned int i = 5;
    while (--i >= 0)
    {
        printf("Hello World\n");
    }
}
a)5
b)6
c)Infinite
d)Program will not compile

ans::c







6. struct emp
{
int age;
char name[10];
struct emp e;
};

void main()
{
            printf(“%d”.sizeof(struct emp));
}

a)24
b) No Output
c) Compiler Error
d) None Of the above
ans::c

7. what is the outpur of the following prog.
            void main()
{
                        insert(root,2);
                        insert(root,1);
                        insert(root,3);
                        insert(root,4);
                        insert(root,5);

                        preorder(root);
}
            assume insert function inserts a node at its correct position in the tree. root is the root of the tree and preorder function prints the nodes as in preorder traversal.

a)1 2 3 4 5
b) 1 2 5 4 3
c) 1 3 4 5 2
d) 2 1 3 4 5

8.
void main()
{
      int x;
push(top,10);
      push(top,20);
      push(top,5);
      push(top,40);
      push(top,1);
      push(top,25);

      x=pop(top);
printf(“%d”, x);
}
consider push function pushes onto the stack the given value. and pop operation performs pop and returns the poped value.

(a)    10 (b) 5 (c) 1 (d) 25

9. if the preorder traversal of a BST tree is 100 50 25 75 200 150 300 then the root of the tree is :
( a) 300 (b) 75 (c) 100 (d) 25

10. The operation for adding an entry to a stack is traditionally called:
a.add   b.append         c.insert             d.push

11. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then removed one at a time, in what order will they be removed?
a.ABCD          b.ABDC          c.DCAB                      d.DCBA

         14
                           /  \
2                11
            / \   / \
           1   3  10  30
         /  /     \       
         7  40      50


12. There is a tree in the box at the top of this section. How many leaves does it have?
A.     5
B.     6
C.     4
D.    9
13. There is a tree in the box at the top of this section. How many of the nodes have at least one sibling?
E.     5
F.      6
G.    7
H.    8
I.       9
14.There is a tree in the box at the top of this section. What is the value stored in the parent node of the node containing 30?
J.       10
K.    11
L.     14
M.   40
N.    None of the above
15.There is a tree in the box at the top of this section. How many descendants does the root have?
O.    0
P.      2
Q.    9
R.     8
16.There is a tree in the box at the top of this section. What is the depth of the tree?
S.      2
T.      3
U.    4
V.    8
W.   9
17.There is a tree in the box at the top of this section. How many children does the root have?
X.    2
Y.    4
Z.     6
     18. What is the value of the postfix expression 6 3 2 4 + - *:
a.       Something between -15 and -100
b.      Something between -5 and -15
c.       Something between 5 and -5
d.      Something between 5 and 15
e.       Something between 15 and 100
    19. Suppose cursor points to a node in a linked list (using the node definition with member functions called data and link). What statement changes cursor so that it points to the next node?
a.       cursor++;
b.      cursor = link;
c.       cursor += link;
d.      cursor = cursor->link;
20. Consider the following  queue which can be allocated eight
integers and five operations.front = 1 rear= 3
Queue =  -,2 , 4 ,5, - , - , -,-
(for notational convenience “ – “ used to denote an empty cell)

The following operations have to be performed.
(i) 6 is added to the queue.
(ii) Two elements are deleted from the queue.
(iii) 10 and 12 are added to the queue.
(iv) Two elements are deleted from the queue.
(v) 2 and 3 are added to the queue.

What are the final front and rear values when the above operations are performed into a circular queue?
(a) front = 7 rear=2
(b) front = 2 rear=0
(c) front = 5 rear=8
(d) front = 5 rear=0

21. Consider the following statements:
          (i) The queue can be implemented by a linked list.
          (ii) The queue can be implemented only by stack.
          (iii) There are references kept at both the front and the back of the list.
          (iv) The Queue can be implemented only by an array-based method.
Which of the above statement(s) is/are valid for the queues?
(a) (i) only
(b) (i),(ii) and (iii) only
(c) (i) and (iii) only
(d) (i),(iii) and (iv) only
(e) (ii) and (iv) only






22. main(){
int i,b[]={1,2,3,4,5},*p;
p=b;
++*p;
Printf(“%d”,*p);
P+=2;
Printf(“%d”,*p);
}
A.    2 3
B.     2 4
C.     3 4
D.    2 5

Ans::2 3

23. void main()
            {
              int a=1,b=2,c=3,d=4,e;
              e=(a,a)+(b,c)+(c,d)-(d,b);
              printf("%d",e);
            }
(a)Compile-Time Error            (b)10                                        (c)6                              (d)2
 
Ans::6
24. struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
 struct aaa abc,def,ghi,jkl;
 int x=100;
 abc.i=0;abc.prev=&jkl;
 abc.next=&def;
 def.i=1;def.prev=&abc;def.next=&ghi;
 ghi.i=2;ghi.prev=&def;
 ghi.next=&jkl;
 jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
 x=abc.next->next->prev->next->i;
 printf("%d",x);
}
 


25. What would be the output if we enter the following data set (in the respective order) into a standard program to construct a Binary search tree?

25, 72, 16, 11, 88, 26, 9, 36, 21, 45, 14, 69



(a)














(b)














(c)















(d)















1)      which of the following data structure is used in hierarchical data modeling
a)      stacks
b)      queues
c)      trees
d)     structure
ans: trees
2)      a binary tree with 20 nodes have _____ null branches
a)      20
b)      22
c)      21
d)     40
Ans: 21
3)      in tree construction which of the following is suitable efficient data structure
a)      array
b)      doubly linked list
c)      stack
d)     queue
e)      none
ans: doubly linked list

4)      find output of the following code.
 
            #define min(a,b) (a<b?a:b)

           main()
          {
                  int a;
                  a=min(3+4,4+4);
                  printf(“%d\n”,a);

                }

a)      7
b)      8
c)      Compile time error
d)     Garbage.
Ans::a

5)      main()
{
float f=2;
switch(f)
{
default: puts(“hi”);
            break;
case 2.0 : puts(“helloo”);
}
}
a)      compile time error
b)      hi
c)      helloo
d)     No output

Ans::a

  1. which finite set of elements that is either empty or is portioned into 3 disjoint subset.
    1. single linked list
    2. double linked list
    3. stack
    4. binary tree
Answer: D

  1. what type of Binary Tree is the following tree below

    1. strictly binary tree
    2. complete binary tree
    3. almost complete binary tree
    4. not a binary tree

Answer: D

  1. Which is the preorder of a Binary tree represented below
    1. ABDHIECFJKG
    2. IHDEBKJFGCA
    3. IHDBEAKJFCG
    4. ABCDEFKJGHI
Answer: A
  1. If suppose root to be deleted then which node will be the root node


    1. B
    2. G
    3. Any node
    4. Both a and b are correct

Answer B
  1. conver this expression in prefix form
(A+B * C/D * E /G – H + I) ^ ( J /K * L)
                       
    1. ^-+//*BC*DEGA+HI/J*KL
    2. ^+-//*BC*DEGA+HI*J/KL
    3. ^-+/*/BC*DEGA+HI*J/KL
    4. ^-+/*/BC*DEGA+HI*J/KL

Answer: A

  1. postfix form of the following expression is
A*B*C*D*E*F/G+H-I^J
                       
    1. -/*****ABCDEFGH+^IJ
    2. AB*C*D*E*F*G/H+IJ^-
    3. BA*D*C*F*GH/+IJ^-
    4. AB*CB*D*E*F/GH*IJ^

  1. which is formula to find the total no. of node in complete B.T
a. tn=2d+1 – 1 where depth(d) !=level
b. tn ==2d+1 – 1  where depth != level(L)
c. tn = 2L+1
d. 2n-1
               
                                Answer:  A

  1. what type of B.T is the following tree

    1. strictly B.T
    2. completely B.T
    3. stricktly complete B.T
    4. almost complete B.T

Answer: A

  1. Considering the following code in which ‘root’ is the root node in binary tree and ‘temp’ and ‘temp1’ are pointers and ‘key’ has only 1 leaf node left

temp=root;
While(tempvalue!=key)
{
temp1=temp;
If(tempvalue<key)
{
temp=tempright;
}
else if(tempvalue>key)
temp=templeft;
}

if(temp1value < key)
temp1right=templeft;

else if(temp1value>key)
            temp1left=templeft;
            free(temp);

                        what is the output after execution of this code?

a.       Deletes the key value node & make leaf node connected to its parent
b.      Deletes the leaf node of key node
c.       Deletes the key node
d.      None of the above

Answer: A





































4 comments:

  1. this should be very helpful.. I got placed in wipro and wud be joining very soon. it was very generous of u to post such amazing useful details!

    ReplyDelete
  2. Anonymous3:47 AM

    Hey there terrific blog! Does running a blog similar
    to this require a lot of work? I have very little understanding of programming
    however I had been hoping to start my own blog in the near future.
    Anyhow, if you have any suggestions or tips for new blog owners please
    share. I understand this is off subject however I simply had
    to ask. Appreciate it!

    my web page ... boarding Kennels

    ReplyDelete
  3. Anonymous1:01 PM

    My brother suggested I would possibly like this web site.
    He was once totally right. This publish actually made my day.
    You can not believe simply how much time I had spent for this
    info! Thanks!

    my blog; recruitment Africa

    ReplyDelete
  4. Anonymous2:41 PM

    At once, you should have the opportunity to see before-and-after photos of those
    that have already tried this treatment. If you happen to remain inside the 5%, it is easy to probably consider cosmetic plastic surgery as your only selection. If you're among the numerous men which has piled on weight over time and are searching for tips on how to lose moobs you may be glad to find out that there are a number of things that it is possible to do to attain this.

    Look into my web blog: Manly

    ReplyDelete