Tuesday 13 February 2018

Data types



1. Can we initialize Enum members at run time? If so how?
2. Declaration & definition?
3. Scope of the variables if it is local ,global & static?
a. int main()                   b. int main()
  {                                {
      int a =10;                       printf(“%d\n”,a)
      printf(“%d\n”,a);             }
      int a =10;                   int a;
      printf(“%d\n”,a);
}
c.int a;                         d. int a =10;
int a=10;                               int a = 10;
int a;                        int main()
int main()                       {
{                                        printf(“%d\n”, a);
     printf(“%d\n”, a);       }
}
4. What is the output of the following program? Justify your answer.
      #include<stdio.h>
      int main()  
      {
        int (*a[5])();
        int i;
        static int j=4;
        static int k=0;
        for(i=0;i<5;i++)
                a[i]=main;
        while(j)
        {
                a[j--]();
        }
        k++;
        printf("%d",k);  
      }

5. Write a program to accept a float value and invert its sign without using arithmetic operators.

6. What is the output of the following code? Justify your answer.
#include<stdio.h>
int main()
{
        char *ptr="Hello"
                      "'\0'"
                         "world";

        printf("%s",ptr);
}

7. #include<stdio.h>
int add(int x, int y)
{
        return (x+y);
}
int subtract(int x, int y)
{
        return(x-y);
}
int multiply(int x, int y)
{
        return(x*y);
}
int main()
{
        int (*fnarry[3])(int,int)={add,subtract,multiply};
        int i=0;
        printf("\n%d\n",(fnarry[i+1]+1)(5,6));
      }

16) storage classes and scope + lifetime
35) scopes and lifetime

37) whether static can be used inside structure, justify.

8.  What is the output of the following code? Justify your answer.
#include <stdio.h>
int main()
{
        unsigned int ui=2;
        ui<<=ui<<=ui;
        printf("%u",ui);
}

9. Explain the type difference between the variables declared as follows:
int (**p)[10];
int *(*q)[10];

10. What is the output of the following program?
#include<stdio.h>
int main()
{
      int i,j,k;
     for(i=0;i<3;i++)
     {
            for(j=0;j<3;j++)
           {
               if(i>0)
                   continue;
               for(k=0;k<3;k++)
                   if(j<1)
                      printf("Hi ");
            }
            printf("Hi ");
      }
}





11. What is the output of the following program? .
#include<stdio.h>
int main()
{
      int a=-1,b=2,c=0;
     b<<=b&&a<c;
     printf("%d",b);
      }

12. Find the bugs in the program
int main()
{
      char c = 0xCF;
      if (c == 0xCF)
         printf("Yes\n");
      else
         printf("No\n";
 }
13. Give additional precedance to the below expression and make the answer as 11 12.0 – 3.0 / 2.0 * 2.0 – 1.0
14. Find the Output ?                                                                                                                                         
Int main() {
char *str = “Hello World”;
str[0] = 'h';
printf(“%s”, str);
}  
answer : segmentation fault.

15. Find the Output ?
int main() {
int i  = 2;
for (i = 0; i <= 3;i++) {
static int i;
i = i + 8;
}
printf(“%d”, i);
}
16. Where typedef will be stored/resolved.
17. Scopes and lifetime.
18. Find the Output ?
int main() {
char i;
for (i = 120; i <= 128; i++) {
printf(“%d\n”, i);
}
}
19. #include <stdio.h>
enum {false,true};
int main()
{
int i=1;
do
     {
printf("%d\n",i);
i++;
if(i < 15)
continue;
      }     while(false);
return 0;
      }

a) prints 1 to 15              b) 1
c) Run Time error              d) 0

20.What is the output
#include <stdio.h>
int main()
{
int i=43, b = 0;
printf("%d\n",printf("%d",printf("%d",i)));
return 0;
   }
a) 4321                       b) 1234
c) Error                      d) None

21. What is the output:
      int main(void)
      {
     int k = 100 ;
     const int *p =&k ;
     *p = 200 ;
     printf(“\n %d”, k );
      }
      a) Compiler Error        b) 100      
c)  200                  d) 0
22. The output of the following is
      int main(void)
      {
           int i=5, j=5;
     while(j-- > 3){
      static int i=10; 
      printf("%d ",i++);
      }
            printf("%d",i);
      }
a) 5 6 7 8                     b) 10 11 12 5
c) 10 11 5                     d) None of these

23. What is the output
      #include<stdio.h>
      int main()
  {
            int a= 1;
            switch(a)
            {
            case '1':
                  printf("ONE\n");
                  break;
            case '2':
                  printf("TWO\n");
                  break;
            case '3':
                  printf("THREE\n");
                  break;
            default:
                  printf("NONE\n");
            }
            return 0;
      }

a) prints ONE            b) prints TWO
c) prints NONE                 d) prints nothing

23. What is the output
      #include<stdio.h>
      int main()
      {
            int a=1;
            switch(a)
            {
                  int b=20;
            case 1:
                  printf("b = %d\n",b);
                  break;
            default:
                  printf("b = %d\n",b);
                  break;
            }
            return 0;
      }

a) b = 20                      b) b = 1
c) Compile Time Error          d) b = Garbage Value





24. What is the Output
      #include <stdio.h>
      int main ( )
      {
            int x, y;
            x = 3, 2, 1;
            y = (3, 2, 1);
            printf("%d %d\n", x, y);
            return 0;
      }

      a) 3 1                  b) Compiler Error
      c) 1, 3                        d) None of these


25. What is the Output
      #include <stdio.h>
      int main(void)
      {
            int i;
            i = 10;
            printf("sizeof(i++) is: %d\t",sizeof(++i));
            printf("i : %d\n",i);
            return 0;
      }
       a) 4 10                       b) 4 11
       c) 4 12                       d) None

26. What is the output of this.
      #include<stdio.h>
      int main(void)
      {
            int x = 0, y = 1, z = 0;
            z = x && ++y;
            printf("%d, %d, %d\n", x, y, z);
            return 0;
      }

      a) 0, 1, 1                     b) 0, 0, 0
      c) 0, 1, 0                        d) None

27. If char=1, int=4, and float=4 bytes size, What will be the output   of the program ?
      #include<stdio.h>
      int main()
      {
            char ch = 'A';
            printf("%d, %d, %d", sizeof(ch), sizeof('A'),                               sizeof(3.14f));
            return 0;
      }
       a) 1, 2, 4                    b) 1, 4, 4
       c) 2, 2, 4                    d) 2, 4, 8

28. The output of the following is
      int main( )
     {
            int a=0xf, b=0xa;
            a=a^b;
            b=a^b;
            a=a^b;
            printf(“ %d %d “, a, b);
            return 0;
      }
a) 10 15                       b) 15 10          
c) 10 10                       d) 15 15

29. What is void, where used.
30. why typecasting at malloc.
31. Add 2 numbers without using + and bitwise op's. Ans.(a - (-b))
32. What is sizeof() operator ? Explain how to implement?



33. What is the output
   int main( )
      {
      int x=0, y = -1;
      (x>y) ? y=1 : x=0;
      printf(“%d %d”, x, y);
      return 0;
      }
      a) 0 -1                       b) 0 1
      c) 1 0                  d) Compiler Error

34. What is the output
      #include<stdio.h>
      int main()
      {
            int a=-1,b=2,c=0;
             b<<=b&&a<c;
            printf("%d",b);
            return 0;
      }

35. What is the Output
      #include <stdio.h>
      #define SIZE 10
      int main()
      {    
      int x = 6, y = -5, z = 0;
      if ( (++x && ++y) || ++z)
            ;
      printf (“%d %d %d\n”, x, y, z);
      return 0;
      }

a) 7 -4 1                      b) 7 -4 0
c) 7 -5 1                      d) 6 -5 0
36. What are storage class and what are advantages and disadvantages of       external  storage class?
37. Differentiate between internal static and external static variable,       with an example?
38. Explain C memory  layout with a diagram?
39. How to convert float to binary ?
40. What is the benefit of using an enum rather than a #defined constant? Explain with an example.
42. What is the Output
      # include <stdio.h>
      int main ()
      {
            int *ptr = 10;
            int x = 15
            printf("%d  %d \n", ptr+x, x + ptr);
            return 0;
      }
         a) Runtime Error                   b) Compiler Error
         c) 70 70                          d) None of the Above

43.  const int a = 10;
      int main ( )
      {
            int *p = &a;
            *p = 5;
            prf ( " %d", a);
      }
44. What is the benefit of using const for declaring constants? 
      Explain with example.
45. Whether static can be used inside structure, justify.
46. sizeof() is a operator or function or macro, justify.
     If its operator whether operator returs?
        // compile time operator.
47. Can a variable be both const and volatile ? When should the volatile      modifier be used.
48. When do you use register storage class specifier, explain with an                                                    example?
49. What is the difference between switch and if-else-if ladder. How it       is internally working ?
50. Explain the difference between break and continue, with an example ?
51. Explain the operators in c with precedence ?
52. What is the difference between char const *p and const char *p ?
53. What is typedef. How it is Different from #define ?
54. Explain the importance of loops, with different scenarios.
55. Explain the different variants of printf and scanf with prototype                and examples.
56. What is the Harm in using goto.
57. Explain comma operator with example.
58. int main(void)
      {
      unsigned char *c;
      c = 'A';
      while (c >= 0)
            printf("%d\n", (*c)++);
      }
What will be the output of above program?
59. Why differentite between big endian and little endian?
60. What are weak symbols, explain its advantages or disadvantages?
61.  int main()
     {
            int a = 10;
            func();
            print(a) // a should print as 20
      }
      func()
      {
            Do Whatever//
      }
62. Implement sizeof() operator.
63. What will be C value?
      int n = 7;
      while(n>0) {
        n = n & (n-1)
        c++;
      }

64. What is diffrence between Macro and Typedef
65. What is garbage collection
66. What is static and their scope as variable and function.
67. Where static, auto and globals are stored.
68. Write a program to swap two numbers.
69. Why do we need static and global variable ?
70. What is extern?
71. Where are local variables stored ?what is the scope?
72. What is the operation performed
      int a = 10, b= 20;
      a^=b^=a^=b^=a^=b^=a;
Ans. Swapping two times ....
73. What is the output?
      main(void)
      {
            int i ;
             for(i = 5; i < 7; i++) {
                   fun();
             }    
      }    
      fun () {
            static int val = 0;
           val++;
           printf("%d\n", val);
      }
74. What is the output?
      main(void)
     {
            int val = 10 ;
            fun(val++);
            printf("%d", val);
      }    
      fun( int i) {
      
            printf("%d\n", --i);
      }    

75.   for( i = 0 ; i < argc ; i++) {
            printf(" %s" , argv[i] );
      }    
what is output - if   input is ./a.out *

76. What is static fuction?
77. What happens if a variable is static within the recursion ?
78. What is constant? Why and Where is it used?  Did u use volatile     variable in your drivers? Which variable do you prefer(in     particular task)?
79. How to access a variable which is defined in one file from another file,not using extern (hint:by passing the variable in a     function,and declaring in the header file)

80. Swap 2 variables without using temporary variables.
81. Int a;  printf(“%u” , &a)  if it prints 67. Is it possible ? (He wants to ask whether the address of integer can be starts with odd address ?)
82. How can you get the environment variables?
83. what does ptr++ and *ptr++ will do?
84. How you declare a constant variable?
85. Explain pre increment and post increment.
86. Diff between preincrement and post increment in case of pointers?
87. What is the output?
void fun(int p)
{
      p=p+1;
      return;
}
int main()
{
      int p = 012
      fun(p);
      printf("%d\n",p);
}


88. What is the output?
int main()
{
      printf("%d\n", argv[argc]);
}
Answer : Compiler error.
If we think argv and argc are declared than answer is 0.

89.
int i;
fun(int j)
{
      int i=0;
      i=i+j;
      printf("%d ",i);
      return;
}
int main()
{
      int j=10;
      fun(j);
      printf("%d %d\n",i,j);
}
Answer : 20 0 10
Example for scope of variables.

90. What is the output?
extern int add(int,int);
extern int i;
int main()
{
      printf("%d",add(100,200));
}
int add(int a, int b)
{
      int i;
      i=a+b;
      return(i);
}

91.
int main()
{
      char c=126;
      c++;
      if (c=='a')
            c--;
      else
            c++;
      printf("%d\n", c);
}
Answer : -128

92. int main()
      {
            printf("");
            printf();
            printf("%d");
      }
      Answer : b is invalid
93. Explain Memory Layout of C Program?
94. What is volatile?is it  disadvantage as it turns off the     optimization? 
95. Diffenentiate between an internal static and external static variable?
96. What are the advantages of auto variables?
97. Which expression always return true? Which always return false?
98.  /* Output after compiling both the files, sony2a.c and sony2b.c */
/* sony2a.c */
#include    <stdio.h>
extern int arr[25];
extern int fun(int *, int );


int main()
{
      fun(arr, sizeof(arr));
}
       
         /* sony2b.c */
*int arr[15];
int fun(int arr[], int len)
{
      if(len > 10)
            printf("HELLO\n");
}

99. What is the output?
#include<stdio.h> 
int i;
int main (void)   
{
      int j = 10;
      fun(i,j);
      printf ("%d %d\n", i,j);
}
fun(int i, int j)
{
      i = j;
      printf ("%d ",j);
}

100. What is the output?
#include       <stdio.h>
int main (void)   
{
      char c = 126;
      c++;
      if(c == 'a')
            c--;

      else
            c++;
      printf("%d\n", c);
}
101. Below code is correct or not?

      int main(void) {
            printf(“%d”, main);
      }

102. What is the output?
#include<stdio.h>
static int b=100;
int main()
{
      static int b=20;
      int i=2,j=3,k;
       
      k= i*b;                       /* want access global static b */
      printf("with global b K=%d\n",k);
      k = j*b;                /* want access local static b */
      printf("with local b K=%d\n",k);
      return 0;
}
103. int main()
{
      func();
      return 0;
}
void func()
{
      int i;
      for(i=0;i<5;i++){
            printf("i=%d\n",i);
            func();
      }
}
Is there any problem with code?if YES.what is it?how do u fix it?

104. #include <stdio.h>
      int main()
      {
            int i = 012;
            fun(i);
            printf("%d\n", i);
      }          
      fun(int i)
      {
            i += 1;
      }

105. What is the size of int or Integer pointer. On what basis does it depend . If it is machine dependent, why is it so ?
106. A code snippet to test your knowledge of Comma Operator.
107. What is static memory allocation and dynamic memory allocation?
108. Write the equivalent expression for x%8?
109. Why n++ executes faster than n+1?
110. What is a modulus operator? What are the restrictions of a modulus operator?
111. Can the sizeof operator be used to tell the size of an array passed to a function?
112. What is a static function?
113. Can math operations be performed on a void pointer?
114. What is the difference between NULL and NUL?
115. What is the difference between far and near?
116. What is the benefit of using an enum rather than a #define constant?
117. Can static variables be declared in a header file?
118. What is the benefit of using const for declaring constants?
119. When should a type cast not be used?
120. When should a type cast be used?
121. Is it acceptable to declare/define a variable in a C header?
122. How can you determine the maximum value that a numeric variable can      hold?
123. How reliable are floating-point comparisons?
124. Can a variable be both const and volatile?
125. When should the volatile modifier be used?
126. When should the register modifier be used? Does it really help?
127. Where typedef will be stored/ resolved
128. Storage Classes Scope and where they will be stored
129. Differnce between Global and staic variables
130. About static and extern.
132. What are the basic datatypes in c?
133. What are static and volatile variables, whats the difference between them? What is the use of volatile qualifier?
134. Where are the locals, globals and static variables stored?
135. How you declare a constant variable?
136. Explain pre increment and post increment.
137. Difference between preincrement and post increment in case of      pointers?

138. Explain Memory Layout of C Program?
139. Write a program to find factorial of number. How can we handle if the result is greater than int or double or long double.
140. Explanation about static variable ?
141. What is static?
142. What is extern? where it will store.
143. Difference between the static and global variables.(about the
scope)
144. Write a function to calculate factorial of a given number(optimized way)
145. What is volatile?is it  disadvantage as it turns off the optimization?

146.
#include       <stdio.h> 
int i;
int main (void)   
{
      int j = 10;
      fun(i,j);
      printf ("%d %d\n", i,j);
}
fun(int i, int j)
{
      i = j;
//    j = i;
      printf ("%d ",j);
}

147. /* Similar type */
#include    <stdio.h>
#define max (a,b) a>b?a:b
int main()
{
      int a = 900;
      int b = 100;
      int c = max(a,b) + 10;
      printf("%d\n", c);
}
149. Explain Storage classes?
150. Explain memory layout?
151. Explain storage classes?
152. Implement modulo operator using bitwise operators.
153. Why dereferencing null pointer is segmentaion fault?
154. Usage of static keyword in functions and variables.
155. Difference between macros and enums interms of memory.
156. Write an API for swapping every 5th element in an array with 4th   element if value is lessthan 100.
157. Two files 1.c and 2.c. How to access a static variable of 1.c in   2.c?
158. Explain storage class? Then specifier?
159. #include<stdio.h>
      static int b=100;
      int main()
      {
            static int b=20;
            int i=2,j=3,k;
       
            k= i*b;                       /* want access global static b */
            printf("with global b K=%d\n",k);
            k = j*b;                /* want access local static b */
            printf("with local b K=%d\n",k);
            return 0;
      }

160. I have 7 hours clock and 5 hours clock how to measure 6 hours?
161. What is the output of below program.
      int main()
      {
             unsigned int a = 100;
            while (a >= 0) {
                  printf(“%d\n”, a);
                  a--;
            }
      }
162. int main()
      {
            unsigned int a = 100;
            while (a > 0) {
                  printf(“%d\n”, a);
                  a--;
            }
      }
163. Implement sizeof operator?
164. What is local and global binding.
165. What is little endian and big endian? WAP to convert little endian to big endian
166. Storage class questions
167. Extern and static question in a program way
168. Difference between Macro and const int?
169. Difference between static variable and static function?
170. int A[100];
     int B[100];
     Write a function to find out which all numbers are repeting?
171. Explain usage of static- when used with variable and Used with function
172. What is extern?
      extern int a=10;
            extern int a;
173. Find size of int without using sizeof operator.
174. Why volatile used and where?
175. About static variable and static function?
176. Why volatile?
177. Take an array for example a[] = {3, -2, -1, 5, -5, 2, -3, 4, 2, -2,      -3}
While traversing the above array, we need to find the last consecutive sume. In the above example (4+2 = 6) will give the largest sum. The output should be something like – a) largest sum b) the numbers taken to compute the same and b) the respective start index and end index
178. If there is consecutive stream of bits coming(0's and 1's), at any point of time, we need to determine if the number is divisible by 3. The numbers of bits can be infinitely large as well.
179. Write a code for endianness conversion with the wihout bitwise operators.
180. Consider the following statement
     num = 10.0 + 2.0 / 3.0 – 2.0 * 2.0
      Reconstruct the statement (using parenthesis ) to get value of num as 11.0
181. Find the output for the following,
int main()
{
      char c ;
      for(c = 120; c <= 128; c++)
      {
            printf(“%d ”,c);
      }
      return 0;
}

181. Can you initialize a variable in header file?

182. Find the output of the following,
int main()
{
      int a = 2;
      for(a = 0; a <= 3; a++ )
      {
      static int a;
      a = a + 8;
      }
      printf(“%d”,a);
      return 0;
      }
183.Write a function to reverse a number
184. Depict the usage of static keyword
185. Explain volatile type qualifier.
186. What is meant by int const volatile a;
187. Difference between macros and inline functions
188. How to extern static variables in other files.
189. Explain Static keyword?? Give a real time example of using Static?
190. Difference between Static array and Dynamic array?? What is their significance?
191. Write a program to convert a hexavalue into decimal using bitwise?
195. Explain about static with real time examples ?
196. Explain about volatile with realtime examples ?
197. Find a given number is odd or even without using conditional      statements like(if,switch,loops,ternary operator).
198. 1.c and 2.c having static int i = 10, while compiling whether it   will give error or not?
199. How will you extract a variable from one file another file?
201. Why we can't change char *s="hello" this value?
202. Find a given number is odd or even without using conditional      statements?
203. I'm having array of 200 elements, the range of each value is 1 to 100, Now you should print values only once, (you should not print a     value more than once).


No comments:

Post a Comment