Tutorials, Free Online Tutorials,It Challengers provides tutorials and interview questions of all technology like java tutorial, android, java frameworks, javascript, core java, sql, php, c language etc. for beginners and professionals.

Breaking

C Aptitude Questions And Answers - ARRAY

---------------------------------- Test Your "C" Skill -------------------------------------

ARRAY  

1.void main()
{
 char arr[]=”Visual C++”
 char *arr= “Visual C++”
 printf(“\n %d %d”, sizeof(a), sizeof(b));
 printf(“\n %d %d”, sizeof(*a), sizeof(*b));

}
Output:- 11 2
                 1  1

2.   For the following statements would arr[3] and ptr[3] fetch the same character?
char arr[]=”ItChallengers”
char *ptr=”ItChallengers

Ans:YES.

3. void main()
    {
        int a[3] = {10, 20, 30};
        int *p = a;
        printf("%p\t%p", p, a);
    }


a) Same address is printed.

b) Different address is printed.

c) Compile time error
d) Nothing

Output:- A

4.What does the following declaration 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

Output:- B

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

Output:- C

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

fun (int **p)
{
  printf(“\n%d”,**p);
}

Output:-   1

7.What would be the o/p of the following program if the array begins at 65442?

void main()
{
 int a[3][4] = {
                         1, 2, 3, 4,
                         4, 3, 2, 1,
                         7, 8, 9, 0
                    };
 printf(“\n %u  %u”, a+1, %a+1);
}

Output:-    65450  65466

8.
void main()
{
  float arr[]= { 12.4, 2.3, 4.5, 6.7};
  printf(“\n %d”, sizeof(arr)/sizeof(arr[0]));
}


Output:-   4

9.   Would the following program compile successfully?
void main()
{
 char a[]= “Hello”;
 char *p= “ItChallengers”;
 a=”ItChallengers”;
 p=”Hello”;
 printf(“\n %s  %s”, a, p);
}

Output:-  NO. Because we may assign a new string to a pointer but not to an array.

10.     What be the output of the following program if the array begins at 65486?
void main()
{
 int arr[]= {12, 14, 15, 23, 45}
 printf(“%u  %u”, arr+1, &arr+1);
} 

      Output: 65488  65496


11.  What would be the o/p of the following program, if the array begins at address 1200?

void main()
{
 int  arr[]={2, 3, 4, 1, 6};
 printf(“%d  %d”, arr, sizeof(arr));
} 

    Output:  1200  10


12.   What would be the O/p of the following program, if the array begind at address 65486?

void main()
{
 int arr[]={12, 14, 15, 23, 45};
 printf(“%u  %u”,arr, &arr);
} 

        Output: 65486  65486


No comments:

Post a Comment