C frequently asked questions

  1. Difference between Structure and Array
ARRAY
STRUCTURE
Array refers to a collection consisting of elements of homogenous data type.
Structure refers to a collection consisting of elements of heterogenous data type.
Array uses subscripts or “[ ]” (square bracket) for element access
Structure uses “.” (Dot operator) for element access
Array is pointer as it points to the first element of the the collection.
Structure is not a pointer
Instantiation of Array objects is not possible.
Instantiation of Structure objects is possible.
Array size is fixed and is basically the number of elements multiplied by the size of an element.
Structure size is not fixed as each element of Structure can be of different type and size.
Bit filed is not possible in an Array.
Bit filed is possible in an Structure.
Array declaration is done simply using [] and not any keyword.
Structure declaration is done with the help of “struct” keyword.
Arrays is a primitive datatype
Structure is a user-defined datatype.
Array traversal and searching is easy and fast.
Structure traversal and searching is complex and slow.
data_type array_name[size];
struct sruct_name{
data_type1 ele1;
data_type2 ele2;};
Array elements are stored in continuos memory locations.
Structure elements may or may not be stored in a continuos memory location.
Array elements are accessed by their index number using subscripts.
Structure elements are accessed by their names using dot operator.

 

2.      Why array index in C starts with 0?

Because the index represents an offset from some memory address, so naturally the address of the first element will be at offset 0.
  1. Can the sizeof operator be used to tell the size of an array passed to a function?
No. There’s no way to tell, at runtime, how many elements are in an array parameter just by looking at the array parameter itself. Remember, passing an array to a function is exactly the same as passing a pointer to the first element.

4.      What is right way to Initialize array?

int num[6] = { 2, 4, 12, 5, 45, 5 };
int n{} = { 2, 4, 12, 5, 45, 5 };
int n{6} = { 2, 4, 12 };
int n(6) = { 2, 4, 12, 5, 45, 5 };
5.     Array elements are always stored in ____________ memory locations.
1.Sequential      2.Random 3.Sequential and Rando.4. None of the above
6.     Let x be an array . which of the following operations are illegal.
1.++x                2.x+1     3.x++   4.x*2
7.     What is the maximum no of dimensions an array in c?
1.       2    2.  8    3. 20    4. Theoratically no limit. The only practical limits are memory size and compilers.
8.    Size of the array is need not to be specified , when?
A.Initialization is a part of definition
B.It is a declaratrion
C.It is a formal parameter
D.All of these
9.     What will be the size of array
typedef char x[10];
x myArray[5];
A.15
B.10
C.50
D.30
E.None of these
10.What does the following declare mean int (*ptr)[10];
A.ptr is array of pointers to 10 integers
B.ptr is a pointer to an array of 10 integers
C.ptr is an array of 10 integers
D.ptr is an pointer to array
11.  Array passed as an argument to a function is interpreted as
A.Address of the array.
B.Values of the first elements of the array.
C.Address of the first element of the array.
D.Number of element of the array.

12.                       What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    char arr[7]="Network";
    printf("%s",arr);
  
}
(A)      Network     
(B)      N        
(C)      network      
(D)     Garbage value       
(E)      Compilation error           
13.                       What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    char arr[11]="The African Queen";
    printf("%s",arr);
  
}
(A)      The African Queen          
(B)      The   
(C)      Queen          
(D)     null   
(E)      Compilation error           
14.                       What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    char arr[20]="MysticRiver";
    printf("%d",sizeof(arr));  
}
(A)      20      
(B)      11      
(C)      12      
(D)     22      
(E)      24      
15.                       What will be output if you will execute following c code?
#include<stdio.h>
void main(){
    int const SIZE=5;
    int expr;
    double value[SIZE]={2.0,4.0,6.0,8.0,10.0};
    expr=1|2|3|4;
    printf("%f",value[expr]);
}
(A)      2.000000   
(B)      4.000000   
(C)      6.000000   
(D)     8.000000   
(E)      Compilation error           
16.                       What will be output if you will execute following c code?
#include<stdio.h>
#define var 3
void main(){
    char data[2][3][2]={0,1,2,3,4,5,6,7,8,9,10,11};
    printf("%o",data[0][2][1]);
}
(A)      5        
(B)      6        
(C)      7        
(D)     8        
(E)      Compilation error
17.                       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.
18.                       What will be output if you will execute following c code?
#include<stdio.h>
int main()
{
    int arr[2];
    arr[3]=10;
    printf("%d",arr[3]);
    return 0;
}
19.                       What will be the output of the program ?
#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
D.        2, 3, 20
20.                       What will be the output of the C program by considering 'b' as a User input?
#include<stdio.h>
int main()
{
            char temp;
            char arr[10] = {1, 2, 3, 4, 5, 6, 9, 8};
            temp = (arr + 1)[2];
            printf("%d\n", temp);
            return 0;
}
A. 2
B. 3
C. 4
21.                       What will be the out put?
#include<stdio.h>
int main()
{
            int a[1][2][3] = {0};
            a[0][1][2] = 5;
            printf("%d",*(*(*(a+0)+1)+2));
            return 0;
}
22.                       What will be the output of the C program?
#include<stdio.h>
int main()
{
            int arr[5][5][5] = {0};
            printf("%d", ( &arr+1 - &arr )); 
            return 0;
}
A. 0
B. Compilation error
C. 1
D. 4
23.                       What will be the output of the C program by considering 'b' as a User input?
#include<stdio.h>
int main(){
            int rows = 3, colums = 4, i, j, k;
            int a[3][4] = {1, 2, 3, 5, 7};
            i = j = k = 00;
            for(i = 0;i<rows;i++)
            for(j = 0;j<colums;j++)
            if(a[k][j]<k)
            k = a[i][j];
            printf("%d\n", k);
            return 0;
}
24.                       What will be the output of the C program?
#include<stdio.h>
int main()
{
            int i = 0;
            printf("Hello");
            char s[4] = {'\b', '\t', '\r', '\n'};
            for(i = 0;i<4;i++){
            printf("%c", s[i]);
}
return 0;
}
25.                       What will be the output of the C program?
#include<stdio.h>
int main()
{
            int i = 0;
            char s[4] = {'\0', '\0', '\0', '\0'};
            for(i = 0;i<4;i++)
            {
                        printf("%c", s[i]);
            }
            return 0;
}
26.                       What will be the output of the C program?
#include<stdio.h>
int main()
{
            int a, b, c;     
            int arr[5] = {1, 2, 3, 25, 7};
            a = ++arr[1];
            b = arr[1]++;
            c = arr[a++];
            printf("%d--%d--%d", a, b, c);
            return 0;
}
27.                       What will be the output of the C program?
#include<stdio.h>
#define arr "abcd"
int main()
{
            printf("%c", arr[2]);
            return 0;
}
28.                       What will be the output of the C program?
#include<stdio.h>
int main()
{
            int arr[1] = {2};
            printf("%d", 0[arr]);
            return 0;
}
29.                       What will be the output of the C program?
#include<stdio.h>
int main()
{
            int arr[3], i = 0;
            while(i < 3)
            {
                        arr[i] = ++i;
            }
            for(i=0; i<3; i++)
            {
                        printf("%d--", arr[i]);
            }
return 0;
}

30.                       What is right way to Initialize array?

A. int num[6] = { 2, 4, 12, 5, 45, 5 };  

B. int n{} = { 2, 4, 12, 5, 45, 5 };  

C. int n{6} = { 2, 4, 12 };  

D. int n(6) = { 2, 4, 12, 5, 45, 5 }

31.                       An array elements are always stored in ________ memory locations.

A.Sequential

B.Random

C.Sequential and Random

D.None of the above

32.                       What is the maximum number of dimensions an array in C may have?

A.2

B.8

C.20

D.50

E.Theoratically no limit. The only practical limits are memory size and compilers.

33.                       What will be printed after execution of the following code?

void main()

{

      int arr[10] = {1,2,3,4,5};

      printf("%d", arr[5]);

}

A.Garbage Value

B.5

C.6

D.0

E.None of these

34.                       What will be the output of the following program?

void main()

{

      char str1[] = "abcd";

      char str2[] = "abcd";

      if(str1==str2)

            printf("Equal");

      else

            printf("Unequal");

}

A. Equal

B. Unequal

C. Error

D. None of these.

 


No comments:

Post a Comment