Sunday, August 10, 2014

C Programming - Arrays

1. 
What will be the output of the program ?
#include<stdio.h>

int main()
{
    int arr[1]={10};
    printf("%d\n", 0[arr]);
    return 0;
}
A.1B.10
C.0D.6
2. 
What will be the output of the program if the array begins at address 65486?
#include<stdio.h>

int main()
{
    int arr[] = {12, 14, 15, 23, 45};
    printf("%u, %u\n", arr, &arr);
    return 0;
}
A.65486, 65488B.65486, 65486
C.65486, 65490D.65486, 65487

3. 
What will be the output of the program ?
#include<stdio.h>

int main()
{
    float arr[] = {12.4, 2.3, 4.5, 6.7};
    printf("%d\n", sizeof(arr)/sizeof(arr[0]));
    return 0;
}
A.5B.4
C.6D.7
4. 
What will be the output of the program if the array begins 1200 in memory?
#include<stdio.h>

int main()
{
    int arr[]={2, 3, 4, 1, 6};
    printf("%u, %u, %u\n", arr, &arr[0], &arr);
    return 0;
}
A.1200, 1202, 1204B.1200, 1200, 1200
C.1200, 1204, 1208D.1200, 1202, 1200
5. 
Which of the following is correct way to define the function fun() in the below program?
#include<stdio.h>

int main()
{
    int a[3][4];
    fun(a);
    return 0;
}
A.
void fun(int p[][4])
{
}
B.
void fun(int *p[4])
{
}
C.
void fun(int *p[][4])
{
}
D.
void fun(int *p[3][4])
{
}

No comments: