Some of the technical Questions may help you..!!

Some technical question to get through before company campus exams ..!!

#include<stdio.h>
main()
{
   char s[20] = "Hello\0Hi";
  
   printf("%d %d", strlen(s), sizeof(s));
}
A - 5 9
B - 7 20
C - 5 20
D - 8 20
--------------------------------------------------------------------------------------------------------------------------
 8 - What actually get pass when you pass an array as a function argument?
A - First value of elements in array
B - Base address of the array
--------------------------------------------------------------------------------------------------------------------------1. 
What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?

A. The element will be set to 0.
B. The compiler would report an error.
C. The program may crash if some important data gets overwritten.
D. The array size would appropriately grow.

Answer: Option C
Explanation:

If the index of the array size is exceeded, the program will crash. Hence "option c" is the correct answer. But the modern compilers will take care of this kind of errors.
Example: Run the below program, it will crash in Windows (TurboC Compiler)
#include<stdio.h>
int main()
{
    int arr[2];
    arr[3]=10;
    printf("%d",arr[3]);
    return 0;
}
 -----------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
    int a[5] = {5, 1, 15, 20, 25};
    int i, j, m;
    i = ++a[1];
    j = a[1]++;
    m = a[i++];
    printf("%d, %d, %d", i, j, m);
    return 0;
}
A. 2, 1, 15
B. 1, 2, 5

c.3, 2, 15 -->is the correct ans

D. 2, 3, 20

D - Address of the last element of array
--------------------------------------------------------------------------------------------------------------------------
int main(int argc, char *argv[])--> for main to access values from cmd
--------------------------------------------------------------------------------------------------------------------------
Q 9 - Which of the following statement shows the correct implementation of nested conditional operation by finding greatest number out of three numbers?
A - max = a>b ? a>c?a:c:b>c?b:c
B - a=b ? c=30;
-------------------------------------------------------------------------------------------------------------------------
Q 3 - Choose the application option for the following program?
#include<stdio.h>
main()
{
   int *p, **q;
  
   printf("%u\n", sizeof(p));
   printf("%u\n", sizeof(q));
}
A - Both the printf() will print the same value
B - First printf() prints the value less than the second.
C - Second printf() prints the value less than the first.
D - Error in the code.
--------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
main()
{
   int i = 1;
  
   while(++i <= 5)
      printf("%d ",i++);
}
A - 1 3 5
B - 2 4
C - 2 4 6
D - 2
-----------------------------------------------------------------------------------------------------------------------
Q 5 - A local variable is stored in ___
A - Code segment
B - Stack segment
C - Heap segment
D - None of the above
--------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
main()
{
   int x = 1;
  
   do
      printf("%d ", x);
   while(x++<=1);
}
A - 1
B - 1 2
C - No output
D - Compile error
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
main()
{
   int a[] = {2,1};
  
   printf("%d", *a);
}
A - 0
B - 1
C - 2
D - Compile error.

Answer : C
Explaination
2, as ‘a’ refers to base address.
----------------------------------------------------------------------------------------------------------------------------------------------------------------
include<stdio.h>
void f(int a[])

   int i;
  
   for(i=0; i<3; i++)
      a[i]++;
}
main()
{
   int i,a[] = {10, 20, 30};
  
   f(a);
   for(i=0; i<3; ++i)
   {
      printf("%d ",a[i]);
   }
}
A - 10 20 30
B - 11 21 31
C - Compile error
D - Runtime error

Answer : B
Explaination
Arrays are always passed by reference.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
    int a[5] = {5, 1, 15, 20, 25};
    int i, j, m;
    i = ++a[1];
    j = a[1]++;
    m = a[i++];
    printf("%d, %d, %d", i, j, m);
    return 0;
}
ans 2 3 15
--------------------------------------------------------------------------------------------------------------------------
2. 
What will be the output of the program ?
#include<stdio.h>
int main()
{
    static int a[2][2] = {1, 2, 3, 4};
    int i, j;
    static int *p[] = {(int*)a, (int*)a+1, (int*)a+2};
    for(i=0; i<2; i++)
    {
        for(j=0; j<2; j++)
        {
            printf("%d, %d, %d, %d\n", *(*(p+i)+j), *(*(j+p)+i),
                                    *(*(i+p)+j), *(*(p+j)+i));
        }
    }
    return 0;
}

A. 1, 1, 1, 1
   2, 3, 2, 3
   3, 2, 3, 2
   4, 4, 4, 4
B. 1, 2, 1, 2
   2, 3, 2, 3
   3, 4, 3, 4
   4, 2, 4, 2
C. 1, 1, 1, 1
   2, 2, 2, 2
   2, 2, 2, 2
   3, 3, 3, 3
D. 1, 2, 3, 4
   2, 3, 4, 1
   3, 4, 1, 2
   4, 1, 2, 3
--------------------------------------------------------------------------------------------------------------------------

include<stdio.h>
int main()
{
    void fun(int, int[]);
    int arr[] = {1, 2, 3, 4};
    int i;
    fun(4, arr);
    for(i=0; i<4; i++)
        printf("%d,", arr[i]);
    return 0;
}
void fun(int n, int arr[])
{
    int *p=0;
    int i=0;
    while(i++ < n)
        p = &arr[i];
    *p=0;
}


A. 2, 3, 4, 5
B. 1, 2, 3, 4 
C. 0, 1, 2, 3
D. 3, 2, 1 0
--------------------------------------------------------------------------------------------------------------------------
4. 
What will be the output of the program ?
#include<stdio.h>
void fun(int **p);
int main()
{
    int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 8, 7, 8, 9, 0};
    int *ptr;
    ptr = &a[0][0];
    fun(&ptr);
    return 0;
}
void fun(int **p)
{
    printf("%d\n", **p);
}


 A. 1
B. 2
C. 3
D. 4
-----------------------------------------------------------------------------------------------------------------------
5. 
What will be the output of the program ?
#include<stdio.h>
int main()
{
    static int arr[] = {0, 1, 2, 3, 4};
    int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
    int **ptr=p;
    ptr++;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    *ptr++;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    *++ptr;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    ++*ptr;
    printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
    return 0;
}


A. 0, 0, 0
   1, 1, 1
   2, 2, 2
   3, 3, 3
B. 1, 1, 2
   2, 2, 3
   3, 3, 4
   4, 4, 1
C.
   1, 1, 1
   2, 2, 2
   3, 3, 3
   3, 4, 4 @

 D. 0, 1, 2
   1, 2, 3
   2, 3, 4
   3, 4, 5

Answer: Option C

--------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
int main()
{
    int size, i;
    scanf("%d", &size);
    int arr[size];
    for(i=1; i<=size; i++)
    {
        scanf("%d", arr[i]);
        printf("%d", arr[i]);
    }
    return 0;
}
A. The code is erroneous since the subscript for array used in for loop is in the range 1 to size.
B. The code is erroneous since the values of array are getting scanned through the loop.
C. The code is erroneous since the statement declaring array is invalid.
D. The code is correct and runs successfully.

Answer: Option C
Explanation:

The statement int arr[size]; produces an error, because we cannot initialize the size of array dynamically. Constant expression is required here.
Example: int arr[10];
One more point is there, that is, usually declaration is not allowed after calling any function in a current block of code. In the given program the declaration int arr[10]; is placed after a function call scanf().

--------------------------------------------------------------------------------------------------------------------------
5. 
Which of the following statements are correct about an array?
1: The array int num[26]; can store 26 elements.
2: The expression num[1] designates the very first element in the array.
3: It is necessary to initialize the array at the time of declaration.
4: The declaration num[SIZE] is allowed if SIZE is a macro.

A. 1
B. 1,4 @
C. 2,3
D. 2,4

Answer: Option B
Explanation:

1. The array int num[26]; can store 26 elements. This statement is true.
2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.
3. It is necessary to initialize the array at the time of declaration. This statement is false.
4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.
Hence the statements '1' and '4' are correct statements.
--------------------------------------------------------------------------------------------------------------------------
2.Which of the following is not a type of constructor?

A. Copy constructor
B. Friend constructor
C. Default constructor
D. Parameterized constructor

3. 
Which of the following statements is correct?

A. Base class pointer cannot point to derived class.
B.
Derived class pointer cannot point to base class. @

C. Pointer to derived class cannot be created.
D. Pointer to base class cannot be created.

Answer: Option B
Explanation:
No answer description available for this question. Let us discuss.

4.Which of the following is not the member of class?
A. Static function
B. Friend function @

C. Const function
D. Virtual function
 Answer: Option B
5. 
Which of the following concepts means determining at runtime what method to invoke?

A. Data hiding
B. Dynamic Typing
C.
Dynamic binding @

D. Dynamic loading

Answer: Option C

Which of the following is the correct way of declaring a function as constant?

[A].   const int ShowData(void) { /* statements */ }
[B].   int const ShowData(void) { /* statements */ }
[C].  
int ShowData(void) const { /* statements */ } @

[D].   Both A and B

Answer: Opt c

Comments

Popular posts from this blog

State space search / blocks world problem by heuristic approach /TIC TAC TOE

Navigation in Vaadin.

Drag and drop items from one Grid to another