Thursday, 23 December 2010

C FAQ'S


1.    int b=10;
 int *p=&b;
*p++;
 printf("%d",*p);
what is the output?
2.    What is the difference between malloc, calloc and realloc?
3.    What does malloc return in C and C++?
4.     main()
{
char *a="hello";
char *b="bye";
char *c="hai";
int x=10,y=100;
c=(x<y>)?a:b;
printf("%s",c);
}
whats the output?
5.     void main()
{
  int a,b;
  a=sumdig(123);
 b=sumdig(123);
 printf("%d %d",a,b);
}
int sumdig(int n)
{
  static int sum;
  int d;
 if(n!=0)
{
d=n%10;
n=(n-d)/10;
  sum=sum+d;
  sumdig(n);
}
else
return s;
}
what is the output?
6.    Declare a pointer to a function that takes a char pointer
as argument and returns a void pointer.
7.    How do we open a binary file in Read/Write mode in C?

  C++ 
8.    class A
{
public:
A()
{
}
~A();
};
class derived:public A
{
derived();
};
what is wrong with this type of declaration?
9.    what do you mean by exception handling?
10. What are "pure virtual" functions?
11. What is the difference between member functions and
static member functions?
12. What is the4 difference between delete[] and delete?
13. Question on Copy constructor.
14. What are namespaces?
15. One question on namespace.
16. What are pass by valu and pass by reference?
what is the disadvantage of pass by value?
I didnt get this. if you have the answer plz tell me.
17. How to invoke a C function using a C++ program?
18. char *str;
char *str1="Hello World";
sscanf(str1,"%s",str);
what is the output?
19. Difference between function overloading and function overriding.
20. There is a base class sub, with a member function fnsub(). There are
two classes super1 and super2 which are subclasses of the base class sub.
if and pointer object is created of the class sub which points to any
of the two classes super1 and super2, if fnsub() is called which one
will be inoked?

1.    void main()
{
  int d=5;
  printf("%f",d);
}Ans: Undefined
2.    void main()
{
  int i;
  for(i=1;i<4,i++)                                                                               
  switch(i)
  case 1: printf("%d",i);break;
{
 case 2:printf("%d",i);break;
 case 3:printf("%d",i);break;
}
 switch(i) case 4:printf("%d",i);
}Ans: 1,2,3,4
3.    void main()
{
 char *s="\12345s\n";
 printf("%d",sizeof(s));
}Ans: 6
4.    void main()
{
  unsigned i=1; /* unsigned char k= -1 => k=255; */
  signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */                                
if(i<j)
  printf("less");
else
if(i>j)
  printf("greater");
else
if(i==j)
  printf("equal");
}Ans: less
5.    void main()
{
  float j;
  j=1000*1000;
  printf("%f",j);
}

1. 1000000
2. Overflow
3. Error
4. None
Ans: 4
6.    How do you declare an array of N pointers to functions returning  pointers to functions returning pointers to characters?     Ans: The first part of this question can be answered in at least        three ways:
7.    Build the declaration up incrementally, using typedefs:
        typedef char *pc;    /* pointer to char */
        typedef pc fpc();    /* function returning pointer to char */
        typedef fpc *pfpc;    /* pointer to above */
        typedef pfpc fpfpc();    /* function returning... */
        typedef fpfpc *pfpfpc;    /* pointer to... */
        pfpfpc a[N];         /* array of... */
8.    Use the cdecl program, which turns English into C and vice versa:        
        cdecl> declare a as array of pointer to function returning   pointer to function returning pointer to char        char *(*(*a[])())()
cdecl can also explain complicated declarations, help with  casts, and indicate which set of parentheses the arguments   go in (for complicated function definitions, like the one   above).  Any good book on C should explain how to read these complicated   C declarations "inside out" to understand them ("declaration mimics use"). The pointer-to-function declarations in the examples above have not included parameter type information. When the parameters have complicated types, declarations can *really* get messy. (Modern versions of cdecl can help here, too.)
9.    A structure pointer is defined of the type time . With 3 fields min,sec hours having pointers to intergers.
    Write the way to initialize the 2nd element to 10.
10. In the above question an array of pointers is declared. Write the statement to initialize the 3rd element of the 2 element to 10
11. int f()
void main()
{
  f(1);
  f(1,2);
  f(1,2,3);
}
f(int i,int j,int k)
{
  printf("%d %d %d",i,j,k);
}What are the number of syntax errors in the above?                   
Ans: None.
12. void main()
{
  int i=7;
  printf("%d",i++*i++);
}Ans: 56
13. #define one 0
#ifdef one
printf("one is defined ");
#ifndef one
printf("one is not defined ");
Ans: "one is defined"
14. void main()
{
  intcount=10,*temp,sum=0;
  temp=&count;
  *temp=20;
  temp=&sum;
  *temp=count;
  printf("%d %d %d ",count,*temp,sum);
}
Ans: 20 20 20
15. There was question in c working only on unix machine with pattern matching.
16. what is alloca()   Ans : It allocates and frees memory after use/after getting out of scope
17. main()
{
  static i=3;
  printf("%d",i--);
  return i>0 ? main():0;
}
Ans: 321
18. char *foo()
{
  char result[100]);
  strcpy(result,"anything is good");                                      
  return(result);
}
void main()
{
  char *j;
  j=foo()
  printf("%s",j);
}
Ans: anything is good.
19. void main()
{
  char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
  char **p;
  p=s;
  printf("%s",++*p);
  printf("%s",*p++);
  printf("%s",++*p);
}Ans: "harma" (p->add(dharma) && (*p)->harma)
"harma" (after printing, p->add(hewlett-packard) &&(*p)->harma)
"ewlett-packard"


Q1.Convert 0.9375 to binary
    a) 0.0111
    b) 0.1011
    c) 0.1111
    d) none
Ans. (c)
Q2.( 1a00 * 10b )/ 1010 = 100
    a) a=0, b=0
    b)a=0, b=1
    c) none
Ans. (b)
Q3. In 32 bit memory machine 24 bits for mantissa and 8 bits for exponent. To increase the range of floating point.
    a) more than 32 bit is to be there.
    b) increase 1 bit for mantissa and decrease 1 bit for exponent
    c) increase 1 bit for exponent and decrease one bit for mantissa
Q4.In C,  "X ? Y : Z "  is equal to
    a) if (X==0) Y ;else Z
    b) if (X!=0) Y ;else Z
    c) if (X==0) Y ; Z
Ans. (b)
Q5. From the following program
           foo()
           int foo(int a, int b)
            {
              if (a&b) return 1;
              return 0;
            }

    a) if either a or b are zero returns always 0
    b) if both a & b are non zero returns always 1
    c) if both a and b are negative returns 0
Q6. The  following function gives some error. What changes have to be made
            void ( int a,int b)
                {
                    int t; t=a; a=b; b=t;
                }
    a) define void as int and write return t
    b) change everywhere a to *a and b to *b
Q7. Which of the following is incorrect
        a) if a and b are defined as int arrays then (a==b) can never be true
        b) parameters are passed to functions only by values
        c) defining functions in nested loops
Q8.  include<stdio.h>
        void swap(int*,int*);
        main()
            {
                int arr[8]={36,8,97,0,161,164,3,9}
                for (int i=0; i<7; i++)
                    {
                for (int j=i+1; j<8;j++)
                if(arr[i]<arr[j]) swap(&arr[i],&arr[j]);
                    }
            }      
        void swap(int*x,int*y)
            {
                int temp; static int cnt=0;
                temp= *x;
                *x=*y;
                *y=temp;
                cnt++;
            }
    What is cnt equal to

a) 7
b) 15
c) 1
d) none of these
Q9.      int main()
                {
                    FILE *fp;
                    fp=fopen("test.dat","w");
                    fprintf(fp,'hello\n");
                    fclose(fp);
                    fp=fopen ("test.dat","w");
                    fprintf (fp, "world");
                    fclose(fp);
                    return 0;
                }

If text.dat file is already present after compiling and execution how many bytes does the file occupy ?

a) 0 bytes
b) 5 bytes
c) 11 bytes
d) data is insufficient
Q10.    f1(int*x,intflag)
            int *y;
            *y=*x+3;
            switch(flag)
                {
                    case 0:
                    *x=*y+1;
                    break;
                    case 1:
                    *x=*y;
                    break;
                    case 2:
                     *x=*y-1; 
                    break;
                }
        return(*y)
      
            main()
            {
                *x=5;
                i=f1(x,0); j=f1(x,1);
                printf("%d %d %d ",i,j,*x);
            }
            
What is the output?

a) 8 8 8
b) 5 8 8
c) 8 5 8
d) none of these
 Technical Questions
1.    main()
  {
  char **p=="Hello";
  printf("%s",**p);                                                                                        
   }
Ans: Garbage or nothing
2.    main()
     {
        printf("%d%c\n");
        printf("%d%c\n");
     }
    Ans: Garbage Value
3.    main()
     {
        int x==5;
        printf("%d%d",x++,++x);
     }
      Ans==6 6
4.     main()
        {
          int x==4;
          printf("%d",printf(" %d %d ",x,x) );
        }
          Ans: 4 4 5
5.    main()
     {
       union                                                                                                    
        {
      int i;
      char p;
      struct
          {
                      int t;
                      char e;
                      char o;
                     }w;
                    };
                printf("%d\n",sizeof(l) );
          }
        Ans: 4
6.    main()
             {
               int i==0,n==6;
               while(n--0);
               i+==n;
               printf("%d\n",i);                                                                                     
               }
          Ans: -1
7.    ain()
               {
                 char a[]=="Hello";
                 printf("%c\n",*a++);
               }
             Ans: Error
8.    a=3,b=2,c=1;
           What's the value of k?
            k== a< b < c-1;
            Ans: 0
9.    main()
               {
              int a=3;
                do
                   {
                      printf("%d", a);
                      a=-1;
                     } while(a0);                                                                                  
                   }
               Ans: 3
10.It is not "exact" Question; But the given Answers is:
       a) PASS1 PASS2
       b) PASS1 FAIL1
       c)FAIL1 FAIL2
      d)FAIL1 PASS2
         main()
               {
                char c==-32;
                int i==-64;
                unsigned u==-26;
                 if(ci)
                 printf("PASS1");
                 if( i < c)
                   printf("PASS2");
                  else
                    printf("FAIL1");
                  if(i<U)
                    printf("PASS2");                                                                       
                   else
                      printf("FAIL2");
                 }
                 Ans: PASS1 PASS2 PASS1
11.main()
    {
       int i==0;
       for( i==0; i<= ;i++)
        {
         switch(i)
           {
             case 0: i+==5;
             case 1: i+==2;
             case 2: i+==5;
             default: i+==4;
             break;
             }
         printf("%d",i);                                                                
       }
    Ans: 16 21
12. main()
  {
     int i==4;
     switch(i)
      {
        case 1:
        printf("HEllo"):
        case default: // "case" should not come with "default"
        printf("****");
      }
   }
  Ans: Error
13.main()
   {
     int sum==0,count;
     for(count==1;sum+==count)
     printf("%d\t",sum);
   }
 Ans: Error
14.define cond(a) a=e && a<=0                                                             
     main()
       {
         char s=='R';
         if( cond(s) )
         printf("UPPER CASE");
          else
          printf("LOWER CASE");
       }
  Ans:UPPER CASE
15.main()
 {
     static int i==5;
      printf("%d\t",i--);
      if( i)
      main();
       }
Ans: 5 4 3 2 1
16.main()
 {
  char *a1=="new",*a2=="dictionary",*t;
  swap(a1,a2);
  printf("(%s%s)",a1,a2);                                                           
  t=¡;
  a1=¢;
  a2==t;
  printf("-(%s%s)",a1,a2);
   }
 swap( char *s1,char *s2)
      {
     char *temp;
     s1=s2;
     s2=s1;
     temp=s1;
     }
  Ans: (newdictionary)-(dictionarynew)
17.*p++?
 Ans: increments Address
18.main()
 {
 int a[]=={ 10,20,30,40,50};
 char*p==(char*)a;
  printf("%d", * ( (int *) p+4);                                                                     
  }
 Ans: 50
19.one question nothig but calling a function before it has been defined.

Instructions:
1. Please ignore any case-sensitive errors and un-included libraries.
2. You may use the back of this question paper for any rough work. 
1.  main()
   {
    int i;
    printf("%d", &i)+1;
    scanf("%d", i)-1;
  }

a. Runtime error.
b. Runtime error. Access violation.
c. Compile error. Illegal syntax
d. None of the above
  
2.  main(int argc, char *argv[])
  {
(main && argc) ? main(argc-1, NULL) : return 0;
  }

a. Runtime error.
b. Compile error. Illegal syntax
c. Gets into Infinite loop
d. None of the above 
3.  main()
{
  int i;
  float *pf;
  pf = (float *)&i;
  *pf = 100.00;
  printf("%d", i);
}

a. Runtime error.
b. 100
c. Some Integer not 100
d. None of the above 
4.  main()
  {
   int i = 0xff;
   printf("%d", i<<2);
  }

a. 4
b. 512
c. 1020
d. 1024 
5.  #define SQR(x) x * x
main()
{
  printf("%d", 225/SQR(15));
}

a. 1
b. 225
c. 15
d. none of the above 
6.  union u
{
 struct st
{
  int i : 4;
  int j : 4;
  int k : 4;
  int l;
 }st;
  int i;
 }u;

main()
 {
  u.i = 100;
  printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}

a. 4, 4, 0
b. 0, 0, 0
c. 100, 4, 0
d. 40, 4, 0 
7.  union u
  {
  union u
   {
   int i;
   int j;
 }a[10];
  int b[10];
 }u;

main()
  {
   printf("%d", sizeof(u));
   printf("%d", sizeof(u.a));
   printf("%d", sizeof(u.a[0].i));
  }
a. 4, 4, 0
b. 0, 0, 0
c. 100, 4, 0
d. 40, 4, 0 
8.  main()
   {
   int (*functable[2])(char *format, ...) ={printf, scanf};
   int i = 100;

   (*functable[0])("%d", i);
   (*functable[1])("%d", i);
   (*functable[1])("%d", i);
   (*functable[0])("%d", &i);
}

   a. 100, Runtime error.
   b. 100, Random number, Random number, Random number.
   c. Compile error
   d. 100, Random number 
9.  main()
{
    int i, j, *p;
    i = 25;
    j = 100;
    p = &i; /* Address of i is assigned to pointer p */
    printf("%f", i/(*p)); /* i is divided by pointer p */
}

a. Runtime error.
b. 1.00000
c. Compile error
d. 0.00000 
10.main()
  {
   int i, j;
   scanf("%d %d"+scanf("%d %d", &i, &j));
   printf("%d %d", i, j);
 }

a. Runtime error.
b. 0, 0
c. Compile error
d. the first two values entered by the user 
11.main()
  {
   char *p = "hello world";
   p[0] = 'H';
   printf("%s", p);
 }

a. Runtime error.
b. “Hello world” c. Compile error
d. “hello world”   
12.main()
  {
 char * strA;
 char * strB = “I am OK”; memcpy( strA, strB, 6);
}

a. Runtime error.
b. “I am OK” c. Compile error
d. “I am O”   
13.How will you print % character?
a. printf(“\%”) b. printf(“\\%”) c. printf(“%%”) d. printf(“\%%”)   
14.const int perplexed = 2;
 #define perplexed 3
main()
 {
  #ifdef perplexed
  #undef perplexed
  #define perplexed 4
  #endif
   printf(“%d”,perplexed); }

a. 0
b. 2
c. 4
d. none of the above 
15.struct Foo
  {
  char *pName;
 };

main()
  {
  struct Foo *obj = malloc(sizeof(struct Foo));
  strcpy(obj->pName,"Your Name");
  printf("%s", obj->pName);
}

a. “Your Name” b. compile error
c. “Name” d. Runtime error 
16.struct Foo
  {
      char *pName;
     char *pAddress;
  };
main()
{
   struct Foo *obj = malloc(sizeof(struct Foo));
   obj->pName = malloc(100);
   obj->pAddress = malloc(100);
   strcpy(obj->pName,"Your Name");
   strcpy(obj->pAddress, "Your Address");
   free(obj);
   printf("%s", obj->pName);
  printf("%s", obj->pAddress);
}

a. “Your Name”, “Your Address” b. “Your Address”, “Your Address” c. “Your Name” “Your Name” d. None of the above 
17.main()
{
 char *a = "Hello ";
 char *b = "World";
 printf("%s", stract(a,b));
}

a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above 
18.main()
{
  char *a = "Hello ";
  char *b = "World";
  printf("%s", strcpy(a,b));
}

a. “Hello” b. “Hello World” c. “HelloWorld” d. None of the above 
19.void func1(int (*a)[10])
{
printf("Ok it works");
}

void func2(int a[][10])
{
  printf("Will this work?");
}

main()
{
  int a[10][10];
  func1(a);
  func2(a);
}

a. “Ok it works” b. “Will this work?” c. “Ok it works Will this work?” d. None of the above 
20.main()
{
  printf("%d, %d", sizeof('c'), sizeof(100));
}

a. 2, 2
b. 2, 100
c. 4, 100
d. 4, 4 
21.main()
{
  int i = 100;
  printf("%d", sizeof(sizeof(i)));
}

a. 2
b. 100
c. 4
d. none of the above 
22.main()
{
  int c = 5;
  printf("%d", main|c);
}

a. 1
b. 5
c. 0
d. none of the above 
23.main()
  {
   char c;
   int i = 456;
   c = i;
   printf("%d", c);
 }

a. 456
b. -456
c. random number
d. none of the above 
24.oid main ()
  {
  int x = 10;
  printf ("x = %d, y = %d", x,--x++);
 }

a. 10, 10
b. 10, 9
c. 10, 11
d. none of the above 
25.main()
  {
   int i =10, j = 20;
   printf("%d, %d\n", j-- , --i);
   printf("%d, %d\n", j++ , ++i);
  }

a. 20, 10, 20, 10
b. 20, 9, 20, 10
c. 20, 9, 19, 10
d. 19, 9, 20, 10 
26.main()
  {
  int x=5;
  for(;x==0;x--) {
  printf(“x=%d\n”, x--); }
 }
a. 4, 3, 2, 1, 0
b. 1, 2, 3, 4, 5
c. 0, 1, 2, 3, 4
d. none of the above 
27.main()
  {
  int x=5;
  for(;x!=0;x--) {
  printf(“x=%d\n”, x--); }
  }
a. 5, 4, 3, 2,1
b. 4, 3, 2, 1, 0
c. 5, 3, 1
d. none of the above 
28.main()
  {
   int x=5;
     {
     printf(“x=%d ”, x--); }
    }
a. 5, 3, 1
b. 5, 2, 1,
c. 5, 3, 1, -1, 3
d. –3, -1, 1, 3, 5  
29.main()
{
  unsigned int bit=256;
  printf(“%d”, bit); }
   {
  unsigned int bit=512;
  printf(“%d”, bit); }
}

a. 256, 256
b. 512, 512
c. 256, 512
d. Compile error 
30.main()
   {
   int i;
   for(i=0;i<5;i++)
    {
    printf("%d\n", 1L << i);
   }
 }
a. 5, 4, 3, 2, 1
b. 0, 1, 2, 3, 4
c. 0, 1, 2, 4, 8
d. 1, 2, 4, 8, 16 
31.main()
{
signed int bit=512, i=5;

for(;i;i--)
{
printf("%d\n", bit = (bit >> (i - (i -1))));
}
}
512, 256, 128, 64, 32
b. 256, 128, 64, 32, 16
c. 128, 64, 32, 16, 8
d. 64, 32, 16, 8, 4
  
32.main()
{
signed int bit=512, i=5;

for(;i;i--)
{
printf("%d\n", bit >> (i - (i -1)));
}
}

a. 512, 256, 0, 0, 0
b. 256, 256, 0, 0, 0
c. 512, 512, 512, 512, 512
d. 256, 256, 256, 256, 256 
33.main()
{
if (!(1&&0))
{
printf("OK I am done.");
}
else
{
printf(“OK I am gone.”); }
}

a. OK I am done
b. OK I am gone
c. compile error
d. none of the above 
34.main()
{
if ((1||0) && (0||1))
{
printf("OK I am done.");
}
else
{
printf(“OK I am gone.”); }
}

a. OK I am done
b. OK I am gone
c. compile error
d. none of the above 
35.main()
{
signed int bit=512, mBit;

{
mBit = ~bit;
bit = bit & ~bit ;

printf("%d %d", bit, mBit);
}
}

a. 0, 0
b. 0, 513
c. 512, 0
d. 0, -513 

Mistral Solutions
C Section

1. What does the following program print?
#include <stio.h>
int sum,count;
void main(void)
{< BR> for(count=5;sum+=--count;)
printf("%d",sum);
}
a. The pgm goes to an infinite loop b. Prints 4791010974 c. Prints 4791001974
d. Prints 5802112085 e. Not sure

2. What is the output of the following program?
#include <stdio.h>
void main(void)
{
int i;< BR> for(i=2;i<=7;i++)
printf("%5d",fno());
}
fno()
{
staticintf1=1,f2=1,f3;
return(f3=f1+f2,f1=f2,f2=f3);
}
a. produce syntax errors b. 2 3 5 8 13 21 will be displayed c. 2 2 2 2 2 2 will be displayed
d. none of the above e. Not sure

3. What is the output of the following program?
#include <stdio.h>
void main (void)
{
int x = 0x1234;
int y = 0x5678;
x = x & 0x5678;
y = y | 0x1234;
x = x^y;
printf("%x\t",x);
x = x | 0x5678;
y = y & 0x1234;
y = y^x;
printf("%x\t",y);
}
a. bbb3 bbb7 b. bbb7 bbb3 c. 444c 4448
d. 4448 444c e. Not sure

4. What does the following program print?
#include <stdio.h>
void main (void)
{
int x;
x = 0;
if (x=0)
printf ("Value of x is 0");
else
printf ("Value of x is not 0");
}
a. print value of x is 0 b. print value of x is not 0 c. does not print anything on the screen
d. there is a syntax error in the if statement e. Not sure

5. What is the output of the following program?
#include <stdio.h>
#include <string.h>
int foo(char *);
void main (void)
{
char arr[100] = {"Welcome to Mistral"};
foo (arr);
}
foo (char *x)
{
printf ("%d\t",strlen (x));
printf ("%d\t",sizeof(x));
return0;
}
a. 100 100 b. 18 100 c. 18 18 d. 18 2 e. Not sure

6. What is the output of the following program?
#include <stdio.h>
display()
{
printf ("\n Hello World");
return 0;
}
void main (void)
{
int (* func_ptr) ();
func_ptr = display;
printf ("\n %u",func_ptr);
(* func_ptr) ();
}
a. it prints the address of the function display and prints Hello World on the screen
b. it prints Hello World two times on the screen
c. it prints only the address of the fuction display on the screen
d. there is an error in the program e. Not sure

7. What is the output of the following program?
#include <stdio.h>
void main (void)
{
int i = 0;
char ch = 'A';
do
putchar (ch);
while(i++ < 5 || ++ch <= 'F');
}
a. ABCDEF will be displayed b. AAAAAABCDEF will displayed
c. character 'A' will be displayed infinitely d. none e. Not sure

8. What is the output of the following program?
#include <stdio.h>
#define sum (a,b,c) a+b+c
#define avg (a,b,c) sum(a,b,c)/3
#define geq (a,b,c) avg(a,b,c) >= 60
#define lee (a,b,c) avg(a,b,c) <= 60
#define des (a,b,c,d) (d==1?geq(a,b,c):lee(a,b,c))
void main (void)
{
int num = 70;
char ch = '0';
float f = 2.0;
if des(num,ch,f,0) puts ("lee..");
else puts("geq...");
}
a. syntax error b. geq... will be displayed c. lee.. will be displayed
d. none e. Not sure

9. Which of the following statement is correct?
a. sizeof('*') is equal to sizeof(int) b. sizeof('*') is equal to sizeof(char)
c. sizeof('*') is equal to sizeof(double) d. none e. Not sure

10. What does the following program print?
#include <stdio.h>
char *rev(int val);
void main(void)
{
extern char dec[];
printf ("%c", *rev);
}
char *rev (int val)
{
char dec[]="abcde";
return dec;
}
a. prints abcde b. prints the address of the array dec
c. prints garbage, address of the local variable should not returned d. print a e. Not sure

11. What does the following program print?
void main(void)
{
int i;
static int k;
if(k=='0')
printf("one");
else if(k== 48)
printf("two");
else
printf("three");
}
a. prints one b. prints two c. prints three
d. prints one three e. Not sure

12. What does the following program print?
#include<stdio.h>
void main(void)
{
enum sub
{
chemistry, maths, physics
};
struct result
{
char name[30];
enum sub sc;
};
struct result my_res;
strcpy (my_res.name,"Patrick");
my_res.sc=physics;
printf("name: %s\n",my_res.name);
printf("pass in subject: %d\n",my_res.sc);
}
a. name: Patrick b. name: Patrick c. name: Patrick
pass in subject: 2 pass in subject:3 pass in subject:0
d. gives compilation errors e. Not sure

13. What does
printf("%s",_FILE_); and printf("%d",_LINE_); do?
a. the first printf prints the name of the file and the second printf prints the line no: of the second printf in the file
b. _FILE_ and _LINE_ are not valid parameters to printf function
c. linker errors will be generated d. compiler errors will be generated e. Not sure

14. What is the output of the following program?
#include <stdio.h>
void swap (int x, int y, int t)
{
t = x;
x = y;
y = t;
printf ("x inside swap: %d\t y inside swap : %d\n",x,y);
}
void main(void)
{
int x;
int y;
int t;
x = 99;
y = 100;
swap (x,y,t);
printf ("x inside main:%d\t y inside main: %d",x,y);
}
a. x inside swap : 100 y inside swap : 99 x inside main : 100 y inside main : 99
b. x inside swap : 100 y inside swap : 99 x inside main : 99 y inside main : 100
c. x inside swap : 99 y inside swap : 100 x inside main : 99 y inside main : 100
d. x inside swap : 99 y inside swap : 100 x inside main : 100 y inside main : 99
e. Not sure

15. Consider the following statements:
i) " while loop " is top tested loop ii) " for loop " is bottom tested loop
iii) " do - while loop" is top tested loop iv) " while loop" and "do - while loop " are top tested loops.
Which among the above statements are false?
a. i only b. i & ii c. iii & i d. ii, iii & iv e. Not sure

16. Consider the following piece of code:
char *p = "MISTRAL";
printf ("%c\t", *(++p));
p -=1;
printf ("%c\t", *(p++));
Now, what does the two printf's display?
a. M M b. M I c. I M d. M S e. Not sure


17. What does the following program print?
#include <stdio.h>
struct my_struct
{
int p:1;
int q:1;
int r:6;
int s:2;
};
struct my_struct bigstruct;
struct my_struct1
{
char m:1;
};
struct my_struct1 small struct;
void main (void)
{
printf ("%d %d\n",sizeof (bigstruct),sizeof (smallstruct));
}
a. 10 1 b. 2 2 c. 2 1 d. 1 1 e. Not sure

18. Consider the following piece of code:
FILE *fp;
fp = fopen("myfile.dat","r");
Now fp points to
a. the first character in the file.
b. a structure which contains a char pointer which points to the first character in the file.
c. the name of the file. d. none of the above. e. Not sure.

19. What does the following program print?
#include <stdio.h>
#define SQR (x) (x*x)
void main(void)
{
int a,b=3;
a = SQR (b+2);
}
a. 25 b. 11 c. 17 d. 21 e. Not sure.

20. What does the declaration do?
int (*mist) (void *, void *);
a. declares mist as a function that takes two void * arguments and returns a pointer to an int.
b. declares mist as a pointer to a function that has two void * arguments and returns an int.
c. declares mist as a function that takes two void * arguments and returns an int.
d. there is a syntax error in the declaration. e. Not sure.


21. What does the following program print?
#include <stdio.h>
void main (void)
{
int mat [5][5],i,j;
int *p;
p = & mat [0][0];
for (i=0;i<5;i++)
for (j=0;j<5;j++)
mat[i][j] = i+j;
printf ("%d\t", sizeof(mat)); < BR> i=4;j=5;
printf( "%d", *(p+i+j));
}
a. 25 9 b. 25 5 c. 50 9 d. 50 5 e. Not sure

22. What is the output of the following program?
#include <stdio.h>
void main (void)
{
short x = 0x3333;
short y = 0x4321;
long z = x;
z = z << 16;
z = z | y;
printf("%1x\t",z);
z = y;
z = z >> 16;
z = z | x;
printf("%1x\t",z);
z = x;
y = x && y;
z = y;
printf("%1x\t",z);
}
a. 43213333 3333 1 b. 33334321 4321 4321 c. 33334321 3333 1
d. 43213333 4321 4321 e. Not sure

23. What is the output of the following program?
#include <stdio.h>
void main (void)
{
char *p = "Bangalore";
#if 0
printf ("%s", p);
#endif
}
a. syntax error #if cannot be used inside main function b. prints Bangalore on the screen
c. does not print anything on the screen
d. program gives an error "undefined symbol if" e. Not sure

24. If x is declared as an integer, y is declared as float, consider the following expression:
y = *(float *)&x;
Which one of the following statments is true?
a. the program containing the expression produces compilation errors;
b. the program containing the expression produces runtime errors;
c. the program containing the expression compiles and runs without any errors;
d. none of the above e. Not sure

25. What is the return type of calloc function?
a. int * b. void * c. no return type: return type is void
d. int e. Not sure
 1.what does p in
const char *p
stands for
p can be changed like this

2.main()
sturct date {
char name[20];
int age ;
float sal;
};
sturct data d ={"rajesh"};
printf("%d%f",d.age,d.sal);
}
tell the output

3.main()
int i=7;
printf("%d"i++*i++);
output

4.void main()
{
int d ;
int i=10;
d =sizeof(++i);
printf("%d");
output

5.difference between
extern int f();
int f();

6.choose correct
(i)stack is automatically cleared
(ii)heap is automatically cleared
(iii)user has to clear stack and heap
(iv)system takes care of ----------

7. What'll be the output:
main()
{char *a,*f();
a=f();
printf("%s",a);
}
char *f()
{return("Hello World");

8.What'll be the output:
main()
{char*a,*f();
a=char*malloc(20*sizeof(char));
a=f();
printf("%s",a);
}
char *f()
{char n[20];
strcpy(n,"Hello World");
return(n);
}
9.What is the error :
main()
{int j=10;
switch(j)
{ case 20:
pritnf("Less than 20");
break;
case 30:
printf("Less than 30");
break;
default:
printf("hello");
}

10.which is valid :
(i)char arr[10];
arr="hello";
(ii) char arr[]="hello";

11.
main()
{
char *str;
str=char*malloc(20*sizeof(char));
strcpy(str,"test");
strcat(str,'!');
printf("%s",str);
}

12. How many times main is get called :
main()
{
printf("Jumboree");
main();
}
ans: till stack overflow.

13. Which statement is true about main :
(i) Varible no. of Arguments can be passed main.
(ii) Main can be called from main();
(iii) We can't pass arguments are passed in main
(iv) main always returns an int

14. Output ?
main()
{
int i,j;
for(i=0,j=0;i<5,j<25;i++,j++);
printf("%d %d",i,j);
}

15.main()
{
int i;
if(i=0) //it's assisnment not logical operator
printf(" Hell ");
else
printf("Heaven");
like this
no negative marking and more than one answers but paper I is cutoff paper i think c paper will not be checked 

1.
static int i;
{
i=10;
...
}
printf("%d",i);
Ans: 10

2.
#define func1(a) #a
#define func2(a,b,c) a##b##c
printf("%s",func1(func2(a,b,c)))
Ans: func2(a,b,c)

3.
const int* ptr;
int* ptr1;
int a=10;
const int p=20;
ptr=a;
ptr1=p;

4.
class a
virtual disp()
{ printf("In a");}
class b:public a
disp()
{ printf("In b");}
class c:public a
disp()
{ printf("In c");}
main()
{
a obj;
b objb;
c objc;
a=objb;
a.disp();
a=objc;
a.disp();
Ans: "In a" "In a"

5.
a="str";
char *b="new str";
char *temp;
malloc(sizeof(temp)+1,....
strcpy(a,temp);
malloc(sizeof(b)+1,....
strcpy(temp,b);

6.
int m,i=1,j=0,k=-1;
m=k++||j++&&i++;
printf("%d...",m,i,j,k);

7.
class x
{
double b;
double *l;
float &c;
}
main()
{
double g=10.34;
double *f=1.3;
float k=9;
x o;
o.b=g;
o.l=f;
o.c=k;
}

Ans: Compiler Error

Write C/C++ code for following:

For all the probs, u will have decide on wht DS to use.... and u'r program must be efficient...explain in detail... (5 Marks)

1. Find the Kth smallest element in a Binary Tree. (5 Marks)

2. Each worker does a job and is given a rating +ve,-ve or Zero.

Find the MaxSubSequenceSum for given no. of workers.

Ex: Workers=6; Ratings={1,0,-1,4,5,-3}

MaxSubSequenceSum=4+5=9 (5 Marks)

3. 1 to N ppl sitting in a circle. Each one passes a hot potato to the next person. After M passes the person holding the potato is eliminated. The last person remaining is winner. Find winner for given N,M.

Ex: N=5, M=2, Winner=4 (5 Marks)

4. Reverse a given Linked List. (5 Marks)

5. There is a file called KnowledgeBase.txt which contains some words. Given a sub-string u have to find all the words which match the word in the file.

Ex: file contains a, ant, and, dog, pen.

If I give "an" I should get o/p as "ant, and" (10 Marks)

6. Company employee have id,level,no. of sub-ordinates under him...

If a emp leaves then his sub-ordinates are assigned to any of the emp's seniors...
Write four functions:

1.    Point out error, if any, in the following program
main()
 {
  int i=1;
  switch(i)
  {
    case 1:
           printf("\nRadioactive cats have 18 half-lives");
           break;
   case 1*2+4:
          printf("\nBottle for rent -inquire within");
          break;
}
}
    Ans. No error. Constant expression like 1*2+4 are acceptable in cases of a switch. 
2.    Point out the error, if any, in the following program                                                       
main()
{
    int a=10,b;
    a>= 5 ? b=100 : b=200;
    printf("\n%d",b);
}
Ans. lvalue required in function main(). The second assignment should be written in parenthesis as follows:
 a>= 5 ? b=100 : (b=200);
3.    In the following code, in which order the functions would be called?
    a= f1(23,14)*f2(12/4)+f3();
     a) f1, f2, f3 b) f3, f2, f1
    c) The order may vary from compiler to compiler d) None of the above
4.    What would be the output of the following program?
main()
{
   int i=4;
   switch(i)
   {
    default:
          printf("\n A mouse is an elephant built by the Japanese");                                       
    case 1:
             printf(" Breeding rabbits is a hair raising experience");
             break;
case 2:
           printf("\n Friction is a drag");
           break;
case 3:
          printf("\n If practice make perfect, then nobody's perfect");
}
}
a) A mouse is an elephant built by the Japanese b) Breeding rabbits is a hare raising experience
c) All of the above d) None of the above
5.    What is the output of the following program?
#define SQR(x) (x*x)
main()
   {
     int a,b=3;
     a= SQR(b+2);
     printf("%d",a);
   }
   a) 25    b) 11 c) error d) garbage value
6.    In which line of the following, an error would be reported?                                    
1. #define CIRCUM(R) (3.14*R*R);
2. main()
3. {
4. float r=1.0,c;
5. c= CIRCUM(r);
6. printf("\n%f",c);
7. if(CIRCUM(r))==6.28)
8. printf("\nGobbledygook");
9. }
a) line 1 b) line 5 c) line 6    d) line 7
7.    What is the type of the variable b in the following declaration?
#define FLOATPTR float*
FLOATPTR a,b;
    a) float b) float pointer c) int d) int pointer
8.    In the following code;
#include<stdio.h>
main()
{
  FILE *fp;
  fp= fopen("trial","r");
 }   
fp points to:
a) The first character in the file.
    b) A structure which contains a "char" pointer which points to the first character in the file.
c) The name of the file. d) None of the above.                                                     
9.    We should not read after a write to a file without an intervening call to fflush(), fseek() or rewind() < TRUE/FALSE>
Ans. True
10.  If the program (myprog) is run from the command line as myprog 1 2 3 , What would be the output?
main(int argc, char *argv[])
{
   int i;
   for(i=0;i<argc;i++)
   printf("%s",argv[i]);
  }
  a) 1 2 3    b) C:\MYPROG.EXE 1 2 3
c) MYP d) None of the above
11. If the following program (myprog) is run from the command line as myprog 1 2 3, What would be the output?
main(int argc, char *argv[])
   {
   int i,j=0;
   for(i=0;i<argc;i++)
   j=j+ atoi(argv[i]);
   printf("%d",j);
  }
a) 1 2 3     b) 6 c) error d) "123"
12. If the following program (myprog) is run from the command line as myprog monday tuesday wednesday thursday,
What would be the output?
main(int argc, char *argv[])
   {
   while(--argc >0)
   printf("%s",*++argv);
  }
  a) myprog monday tuesday wednesday thursday     b) monday tuesday wednesday thursday
c) myprog tuesday thursday d) None of the above                                                   
13. In the following code, is p2 an integer or an integer pointer?
 typedef int* ptr
 ptr p1,p2;
 Ans. Integer pointer
14. Point out the error in the following program
main()
   {
   const int x;
   x=128;
   printf("%d",x);
  }
    Ans. x should have been initialized where it is declared.
15. What would be the output of the following program?
 main()
  {
   int y=128;
   const int x=y;
   printf("%d",x);
 }
    a) 128 b) Garbage value c) Error d) 0
16.  What is the difference between the following declarations?                                        
   const char *s;
   char const *s;
  Ans. No difference
17. What would be the output of the following program?
  main()
    {
    char near * near *ptr1;
    char near * far *ptr2;
    char near * huge *ptr3;
    printf("%d %d %d",sizeof(ptr1),sizeof(ptr2),sizeof(ptr3));
   }
     a) 1 1 1         b) 1 2 4       c) 2 4 4    d) 4 4 4
18. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char*argv[])
  {
   printf("%c",**++argv);
  }
  a) m     b) f c) myprog d) friday
19. If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?                                                                                    
 main(int argc, char *argv[])
   {
    printf("%c",*++argv[1]);
     }
    a) r b) f c) m d) y
20.  If the following program (myprog) is run from the command line as myprog friday tuesday sunday,
What would be the output?
main(int argc, char *argv[])
   {
  while(sizeofargv)
  printf("%s",argv[--sizeofargv]);
  }
a) myprog friday tuesday sunday b) myprog friday tuesday
c) sunday tuesday friday myprog d) sunday tuesday friday                               
21.  Point out the error in the following program
main()
  {
   int a=10;
   void f();
   a=f();
   printf("\n%d",a);
   }
   void f()
    {
    printf("\nHi");
    }
    Ans. The program is trying to collect the value of a "void" function into an integer variable.
22.  In the following program how would you print 50 using p?
main()
   {
    int a[]={10, 20, 30, 40, 50};
    char *p;
    p= (char*) a;
   }
    Ans. printf("\n%d",*((int*)p+4));
23.  Would the following program compile?
main()
  {
   int a=10,*j;
   void *k;
   j=k=&a;
   j++;
   k++;
   printf("\n%u%u",j,k);
}
 a) Yes b) No, the format is incorrect
 c) No, the arithmetic operation is not permitted on void pointers                     
d) No, the arithmetic operation is not permitted on pointers
24. According to ANSI specifications which is the correct way of declaring main() when it receives command line arguments?
a) main(int argc, char *argv[]) b) main(argc,argv) int argc; char *argv[];
c) main() {int argc; char *argv[]; } d) None of the above
25. What error would the following function give on compilation?
  f(int a, int b)
      {
     int a;
     a=20;
     return a;
      }
a) missing parenthesis in the return statement b) The function should be declared as int f(int a, int b)
    c) redeclaration of a    d) None of the above                                            
26. Point out the error in the following program
main()
    {
     const char *fun();
     *fun()='A';
    }
   const char *fun()
    {
     return "Hello";
   }
    Ans. fun() returns to a "const char" pointer which cannot be modified
27. What would be the output of the following program?
main()
   {
    const int x=5;
    int *ptrx;
    ptrx=&x;
    *ptrx=10;
    printf("%d",x);
 }
   a) 5      b) 10 c) Error d) Garbage value
28. A switch statement cannot include
    a) constants as arguments b) constant expression as arguments                              
    c) string as an argument d) None of the above
29. How long the following program will run?
main()
{
printf("\nSonata Software");
main();
}
a) infinite loop     b) until the stack overflows
c) All of the above d) None of the above
30. On combining the following statements, you will get char*p; p=malloc(100);
    a) char *p= malloc(100) b) p= (char*)malloc(100)
c) All of the above d) None of the above
31. What is the output of the following program?
main()
  {
   int n=5;
   printf("\nn=%*d",n,n);
  }
a) n=5   b) n=5   c) n= 5 d) error

MOTOROLA PSGTECH 2003
There were basically 3 papers -software ,DSP, Semiconductor software paper (20 questions 45 minutes) concentrate more on data structures 10 questions from data structures and 10 from C++ and data structures10 questions were in the fill in the blank format and 10 questions were multiple choice questions.
1.    bubble sorting is
a)two stage sorting                                                         
b).....
c)....
d)none of the above
2.    .c++ supports
a) pass by value only
b) pass by name
c) pass by pointer
d) pass by value and by reference
3.    .Selection sort for a sequence of N elements
no of comparisons = _________
no of exchanges = ____________
4.    Insertion sort
no of comparisons = _________
no of exchanges = ____________
5.    what is a language?
a) set of alphabets
b)set of strings formed from alphabets
c)............
d)none of the above
6.    Which is true abt heap sort
a)two method sort
b)has complexity of O(N2)
c)complexity of O(N3)
d)..........
7.    In binary tree which of the following is true                                    
a)binary tree with even nodes is balanced
b)every binary tree has a balance tree
c)every binary tree cant be balanced
d)binary tree with odd no of nodes can always be balanced
8.    Which of the following is not conducive for linked list implementation of array
a)binary search
b)sequential search
c)selection sort
d)bubble sort
9.    In c++ ,casting in C is upgraded as
a)dynamic_cast
b)static_cast
c)const_cast
d)reintrepret_cast
10. Which of the following is true abt AOV(Active On Vertex trees)
a)it is an undirected graph with vertex representing activities and edges representing precedence relations
b)it is an directed graph "" "" """ "" "" "" "" "" "
c)........
d).......
11. Question on worst and best case of sequential search                      
12. question on breadth first search
13. char *p="abcdefghijklmno"
then printf("%s",5[p]);
14.  what is the error
struct { int item; int x;}
main(){ int y=4; return y;}
error:absence of semicolon
15. Which of the following is false regarding protected members
a)can be accessed by friend functions of the child
b) can be accessed by friends of child's child
c)usually unacccessible by friends of class
d) child has the ability to convert child ptr to base ptr
16. What is the output of the following
void main()
{
int a=5,b=10;
int &ref1=a,&ref2=b;
ref1=ref2;
++ ref1;
++ ref2;
cout<<a<<b<<endl;                                                        
} value of a and b
a)5 and 12
b)7 and 10
c)11 and 11
d)none of the above
17. What does this return
f(int n)
{
return n<1?0:n==1?1:f(n-1)+f(n-2)
}
hint:this is to generate fibonacci series
code for finding out whether a string is a palindrome,reversal of linked list, recursive computation of factorial with
blanks in the case of some variables.we have to fill it out
18. for eg; for palindrome
palindrome(char * inputstring)
{
int len=strlen ( ?);
int start= ?;
end =inputstring + ?-?;
for(; ?<end && ?==?;++ ?,--?);
return(?==?); }
we have to replace the question marks(?) with corresponding variables
19. .linked list reversal
Linked (Link *h)
{
Link *temp,*r=0,*y=h;                                                         
while(y!= ?) (ans:Null)
{
temp = ?;(ans:y->next)
some code here with similar fill in type
}
20. fill in the blanks type question involving recursive factorial computation

1.           Technical 
2.    What is the output of the following program?<?xml:namespace prefix = o ns urn:schemas -microsoft-com office:office" "
  #include<stdio.h>
  #include<math.h>
  void main( )
    {
      int a=5,b=7;
      printf(“%d\n”,b\a);
   }
   A. 1.4
   B. 1.0
   C. 1
   D. 0
3.    What is the output of the following program listing?                                            
#include<stdio.h>
 void main ( )
  {
   int x,y:
   y=5;
   x=func(y++);
   printf(“%s\n”,
   (x==5)?”true”;”false”);
  }
     int func(int z)
     {
      if (z== 6)
        return 5;
      else
        return 6;
}
  A True
  B false
  C either a or b
  D neither a nor b
4.    What is the output of the following progarm?                                                        
 #include<stdio.h>
   main( )
   {
    int x,y=10;
    x=4;
    y=fact(x);
    printf(“%d\n”,y);
  }
    unsigned int fact(int x)
     {
         return(x*fact(x-1));
     }
   A. 24
   B. 10
   C. 4
   D. none
5.    Consider the following C program and chose collect answer
  #include<stdio.h>
  void main( )
   {
     inta[10],k;
     for(k=0;k<10;k++)
      { a[k]=k;}
     printf (“%d\n”,k);
  }
   A. value of k is undefined ; unpredictable answer                                 
   B. 10
   C. program terminates with run time error
   D. 0
6.    Consider the prog and select answer
   #include<stdio.h>
     void main ( )
      {
         int k=4,j=0:
         switch (k)
         {
            case 3: j=300;
            case 4: j=400:
            case 5: j=500;
         }
           printf (“%d\n”,j);
  }
      A. 300
      B. 400
      C. 500
      D. 0   
7.     Consider the following statements:
    Statement 1 A union is an object consisting of a sequence of named members of various types
    Statement 2 A structure is a object that contains at different times, any one of the several members of various types
    Statement 3: C is a compiled as well as an interpretted language
    Statement 4: It is impossible to declare a structure or union containing an instance of itself
      A. all the statements are correct                                                                      
      B. except 4 all are correct
      C. statemnt 3 is only correct
      D. statement 1,3 are incorrect either 2 or 4 is correct
8.    consider the following program listing and select the output
  #include<stdio.h>
    main ( )
      {
        int a=010,sum=0,tracker:
        for(tracker=0;tracker<=a;tracker++)
        sum+=tracker;
        printf(“ %d\n”,sum);}
        A. 55
        B. 36
        C. 28
        D. n
9.    Spot the line numbers , that are valid according to the ANSI C standards?
 Line 1: #include<stdio.h>
 Line 2: void main()
 Line 3: {
        4 : int *pia,ia;
        5 :float *pafa,fa;                                                                                       
        6 :ia=100;
        7 :fa=12.05;
        8 :*pfa=&ia;
        9 :pfa=&ia;
      10 :pia=pfa;
      11 :fa=(float)*pia;
      12 :fa=ia;
      13 :}
          a. 8 and 9
          b. 9 and 10
          c. 8 and 10
          d. 10 and 11
10.What is the o/p of the follow pgm?
  #include<stdio.h>
   main()
     {
      char char_arr[5]=”ORACL”;
      char c=’E’;
      prinf(“%s\n”,strcat(char_arr,c));                                                  
    }
   a: oracle
   b. oracl
   c. e
   d. none
11.consider the following pgm listing
 #include<stdio.h>
   main()
    {
     int a[3];
     int *I;
     a[0]=100;a[1]=200;a[2]=300;
     I=a;
     printf(“%d\n”, ++*I);            
     printf(“%d\n”, *++I);            
     printf(“%d\n”, (*I)--);            
     printf(“%d\n”, *I);            
   }
        what is the o/p
a.  101,200,200,199
b.  200,201,201,100
c.  101,200,199,199
d.  200,300,200,100   
12. which of the following correctly declares “My_var” as a pointer to a function that returns an integer
   a. int*My_Var();
   b. int*(My_Var());
   c. int(*)My_Var();
   d. int(*My_Var)();
13. what is the memory structure employed by recursive functions in a C pgm?
  a. B tree
  b. Hash table
  c. Circular list
  d. Stack
14.Consider the follow pgm listing?
Line 1: #include<stdio.h>
       2: void main()
       3: {
       4: int a=1;
       5: const int c=2;
       6: const int *p1=&c;
       7: const int*p2=&a;
       8: int *p3=&c;
       9: int*p4=&a;
15.what are the lines that cause compilation errors?                                          
  a.  7
  b.  8
  c.  6 and 7
  d.  no errors
16.what will be the o/p
  #include<stdio.h>
    main()
      {
        inta[3];
        int *x;
        int*y;
       a[0]=0;a[1]=1;a[2]=2;
       x=a++;
       y=a;
       printf(“%d %d\n”, x,(++y));
   }
       a. 0,1
       b. 1,1
       c. error
       d. 1,2
what is the procedure for swapping a,b(assume that a,b and tmp are of the same type?
   a. tmp=a; a=b;b=temp;
   b. a=a+b;b=a-b;a=a-b;                                                                               
   c. a=a-b;b=a+b;a=b-a;
   d. all of the above
 . What is the output of the following program?
#include <stdio.h>
void main()
{
printf("\n10!=9 : %5d",10!=9);
}
1<------ans
0
Error
None of these options
17. #include<stdio.h>
void main()
{
int x=10;
(x<0)?(int a =100):(int a =1000);
printf(" %d",a);
}
Error<------ans
1000
100
None of these options
18. Which of the following shows the correct hierarchy of arithmetic operations in C
(), **, * or /, + or -
(), **, *, /, +, -
(), **, /, *, +, -
(), / or *, - or + <-----Ans

19. What is the output of the following code?
#include<stdio.h>
void main()
{
int a=14;
a += 7;
a -= 5;
a *= 7;
printf("\n%d",a);
}
112<------ans
98
89
None of these options

20. What is the output of the following code? #include<stdio.h>
#define T t
void main()
{
char T = `T`;
printf("\n%c\t%c\n",T,t);
}
Error
T t
T T
t t

21. The statement that prints out the character set from A-Z, is
for( a = `z`; a < `a`; a = a - 1)
printf("%c", &a);
for( a = `a`; a <= `z`; a = a + 1
printf("%c", &a);
for( a = `A`; a <= `Z`; a = a + 1)<----Ans printf("%c", a);
for( a = `Z`; a <= `A`; a = a + 1)
printf("%c", a);
22. The statement which prints out the values 1 to 10 on separate lines, is
for( count = 1; count <= 10; count = count + 1) printf("%d\n",count);
for( count = 1; count < 10; count = count + 1) printf("%d\n",count);<------ans
for( count = 0; count <= 9; count = count + 1) printf("%d ",count);
for( count = 1; count <> 10; count = count + 1) printf("%d\n",count);
23. What does the term `call-by-reference` refer to?
Passing a copy of a variable into a function. Passing a pointer to a variable into a function. <------ans
Choosing a random value for a variable.
A function that does not return any values.

24. What is the output of the following code? #include<stdio.h>
void swap(int&, int&);
void main()
{
int a = 10,b=20;
swap (a++,b++);
printf("\n%d\t%d\t",a, b);
}
void swap(int& x, int& y)
{
x+=2;
y+=3;
}
14, 24
11, 21 <------ans
10, 20
Error
25. What is the output of the following program code
#include<stdio.h>
void abc(int a[])
{
a++;
a[1]=612;
}
main()
{
char a[5];
abc(a);
printf("%d",a[4]);
}
100
612
Error<------ans
None of these options
26. which of the following is true about recursive function
i. it is also called circular definition
ii. it occurs when a function calls another function more than once
iii. it occurs when a statement within the function calls the function itself
iv. a recursive function cannot have a return statement within it"
i and iii<------ans
i and ii
ii and iv
i, iii and iv
27.What will happen if you assign a value to an element of an array whose subscript exceeds the size of the array?
The element will be set to 0
Nothing, its done all the time
Other data may be overwritten
Error message from the compiler

28. What is the output of the following code? #include<stdio.h>
void main()
{
int arr[2][3][2]={{{2,4},{7,8},{3,4},}, {{2,2},{2,3},{3,4}, }}; printf("\n%d",**(*arr+1)+2+7);
}
16 <------ans
7
11
Error
29. If int s[5] is a one dimensional array of integers, which of the following refers to the third element in the array?
*( s + 2 ) <------ans
*( s + 3 )
s + 3
s + 2

30. #include"stdio.h"
main()
{
int *p1,i=25;
void *p2;
p1=&i;
p2=&i;
p1=p2;
p2=p1;
printf("%d",i);
}
The output of the above code is :
Program will not compile <------ans
25
Garbage value
Address of I
31. What is the output of the following code? void main()
{
int i = 100, j = 200;
const int *p=&i;
p = &j;
printf("%d",*p);
}
100
200 <------ans
300
None of the above

32. void main()
{
int i=3;
int *j=&i;
clrscr();
printf("%d%d",++*j,*(&i));
}
What is the output of this program?
3 3
4 3 <------ans
4,address of i printed
Error:Lvalue required
33. What is the output of the following code? #include<stdio.h>
void main()
{
int arr[] = {10,20,30,40,50};
int *ptr = arr;
printf("\n %d\t%d\t",*ptr++,*ptr);
}
10 20
10 10<------ans
20 20
20 10

34. Which of these are reasons for using pointers?
1.To manipulate parts of an array
2.To refer to keywords such as for and if
3.To return more than one value from a function 4.To refer to particular programs more conveniently
1 & 3 <------ans
Only 1
Only 3
All of the above

35. struct num
{
int no;
char name[25];
};
void main()
{
struct num n1[]={{25,"rose"},{20,"gulmohar"}, {8,"geranium"},{11,"dahalia"}};
printf("%d%d" ,n1[2].no,(*&n1+2)->no+1);
}
What is the output of this program?
8 8
8 9 <------ans
9 8
8 , unpredictable
36. During initializing a union

Only one member can be initialised.
All the members will be initialised. Initialisation of a union is not possible.<------ans
None of these options
37. Self referential structure is one
a. Consisting the structure in the parent structure
b. Consisting the pointer of the structure in the parent structure
Only a
Only b
Both a and b
Neither a nor b
38. Individual structure member can be initialized in the structure itself
True
False
Compiler dependent
None of these options

39. Which of the following is the feature of stack?
All operations are at one end
It cannot reuse its memory
All elements are of different data types
Any element can be accessed from it directly<------ans
40. When stacks are created
Are initially empty<------ans
Are initialized to zero
Are considered full
None of these options

41. What is time required to insert an element in a stack with linked implementation?
(1)
(log2n)<------ans
(n)
(n log2n)

42. Which of the following is the feature of stack?
All operations are at one end
It cannot reuse its memory
All elements are of different data types
Any element can be accessed from it directly<------ans
43. Time taken for addition of element in queue is
(1)
(n)
(log n)<------ans
None of these options
44. When is linear queue said to be empty ? Front==rear
Front=rear-1
Front=rear+1
Front=rear<------ans

45. When queues are created
Are initially empty<------ans
Are initialized to zero
Are considered full
None of the above

46. What would be the output of the following program?
#include <stdio.h>
main()
{
printf("\n%c", "abcdefgh"[4]);
}
abcdefgh
d
e <------ans
error

47. Select the correct C code which will read a line of characters(terminated by a \n) from input_file into a character array called buffer. NULL terminate the buffer upon reading a \n.

int ch, loop = 0; ch = fgetc( input_file ); while( (ch != `\n`)&& (ch != EOF) ){buffer[loop] = ch; loop++; ch = fgetc(input_file );} buffer[loop] = NULL;

int ch, loop = 0; ch = fgetc( input_file ); while( (ch = "\n")&& (ch = EOF)) { buffer[loop] = ch; loop--; ch = fgetc(]input_file ); } buffer[loop]= NULL;
int ch, loop = 0; ch = fgetc( input_file ); while( (ch <> "\n")&& (ch != EOF) ) { buffer[loop] = ch; loop++; ch = fgetc(input_file ); } buffer[loop] = -1;
None of the above
48. What is the output of the following code ?
void main()
{
int a=0;
int b=0;
++a == 0 || ++b == 11;
printf("\n%d,%d",a,b);
}
0, 1
1, 1 <------ans
0, 0
1, 0

49. What is the output of the following program? #define str(x)#x
#define Xstr(x)str(x)
#define oper multiply
void main()
{
char *opername=Xstr(oper);
printf("%s",opername);
}
opername
Xstr
multiply <------ans
Xstr

50. What is the output of the following code ? #include<stdio.h>
#include<string.h>
void main()
{
char *a = "C-DAC\0\0ACTS\0\n"; printf("%s\n",a); }
C-DAC ACTS
ACTS
C-DAC <------ans
None of these

51. #include<stdio.h>
void main()
{
while (1)
{if (printf("%d",printf("%d")))
break;
else
continue;
}
}
The output is
Compile time error
Goes into an infinite loop
Garbage values <------ans
None of these options
52. Select the correct C statements which tests to see if input_file has opened the data file successfully.If not, print an error message and exit the program.
if( input_file == NULL ) { printf("Unable to open file.\n");exit(1); }


if( input_file != NULL ) { printf("Unable to open file.\n");exit(1); }
while( input_file = NULL ) { printf("Unable to open file.\n");exit(1);}
None of these options
53.The code
int i = 7;
printf("%d\n", i++ * i++);
prints 49
prints 56 <------ans
is compiler dependent
expression i++ * i++ is undefined
54. Recursive procedure are implemented by
Linear list
Queue
Tree
Stack<------ans

55. Which of these are reasons for using pointers?
1. To manipulate parts of an array
2. To refer to keywords such as for and if
3. To return more than one value from a function 4. To refer to particular programs more conveniently
1 & 3<------ans
only 1
only 3
None of these options

56. The expression x = 4 + 2 % -8 evaluates to -6
6
4
None of these options

57. What is the output of the following code? #include<stdio.h>
main()
{
register int a=2;
printf("\nAddress of a = %d,", &a); printf("\tValue of a = %d",a);
Address of a,2 <------ans
Linker error
Compile time error
None of these options

58. What is the output of the following code? #include<stdio.h>
void main()
{
int arr[]={0,1,2,3,4,5,6};
int i,*ptr;
for(ptr=arr+4,i =0; i<=4; i++) printf("\n%d",ptr[-i]);(as the 0=4,for -1 it becomes =3)
}
Error
6 5 4 3 2
0 garbage garbage garbage garbage
4 3 2 1 0 <------ans

59. Which of the following is the correct way of declaring a float pointer:
float ptr;
float *ptr; <------ans
*float ptr;
None of the above
60.If the following program (newprog) is run from the command line as:newprog 1 2 3 What would be the output of the following?
void main (int argc, char*argv[])
{
int I,j=0;
for (I=0;I<argc;I++)
j=j + atoi(argv[I]);
printf("%d",j);
}
123
6
123
Compilation error<------ans
  

No comments:

Post a Comment