Sunteți pe pagina 1din 6

WORKSHEET6

1. What would be the output of the following program?


#include <stdio.h>
main()
{
int arr[] = {12, 13, 14, 15, 16};
printf("%d %d %d \n", sizeof(arr), sizeof(*arr), sizeof(arr[0]));
}
2. What would be the equivalent pointer expression for referring the same element as a[i][j][k][l]?

3. What would be the output of the following program assuming that the array begins at location
1002?
#include <stdio.h>
main()
{
int a[3][4] = { 1,2,3,4,
5,6,7,8,
9,10,11,12
};
printf("\n %u \t %u \t %u", a[0]+1, *(a[0]+1), *(*(a+0)+1));
}

4. What would be the output of the following program assuming that the array begins at location
1002?
#include <stdio.h>
main()
{
int a[2][3][4] = {
{
1,2,3,4,
5,6,7,8,
9,1,1,2
},
{
2,1,4,7,
6,7,8,9,
0,0,0,0
}
};

printf("\n %u \n %u \n %u \n %d \n", a, *a, **a, ***a);


}

5. In the following program add a statement in the function fun() such that address of a gets stored in
j.
#include <stdio.h>
main()
{
int *j; void fun(int **); fun(&j);
}
void fun(int ** k)
{
int a = 10;
/* add statement here */
}

6. Would the following program compile?


#include <stdio.h>
main()
{
int a = 10, *j;
void *k;
j = k =&a;
j++;
k++;
printf("\n%u%u", j, k);
}

7. Would the following code compile successfully?


#include <stdio.h>
main()
{
printf("%c", 7["Sundaram"]);
}

8. What would be the output of the following program, if the array begins at address 1200?
#include <stdio.h>

main()
{
int arr[] = {2, 3, 4, 1, 6};
printf("%d\t%d", arr, sizeof(arr));
}

9. What would be the output of the following program?


#include <stdio.h>
main()
{
char str[7] = "Strings";
printf("%s", str);
}

10. What would be the output of the following program?


#include <stdio.h>
main()
{
char ch = 'A';
printf("%d\t%d", sizeof(ch), sizeof('A'));
}

11. What would be the output of the following program?


#include <stdio.h>
main()
{
printf("\n%d%d%d", sizeof('3'), sizeof("3"), sizeof(3));
}
12. What would be the output of the following program?
#include <stdio.h>
main()
{
char *str[] = {"Frogs", "Do", "Not", "Die.", "They", "Croak!"};
printf("%d\t%d", sizeof(str), sizeof(str[0]));
}

13. What would be the output of the following program, if the array begins at 65486?
#include <stdio.h>
main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u\t%u\t%u", arr, arr+1, &arr+1);
}

14. In the following program how would you print 50 using p?


#include <stdio.h>
main()
{
int a[] = {10, 20, 30, 40, 50};
char *p;
p = (char *) a;
}

15. Would the following program compile successfully?


#include <stdio.h>
main()
{
char a[] = "Sunstroke";
char *p = "Coldwave";
a = "Coldwave";
p = "Sunstroke";
printf("\n%s%s", a, p);
}

16. What would be the output of the following program if the array begins at 65472?
#include <stdio.h>
main()
{
int a[3][4] = { 1,2,3,4,
4,3,2,1,
7,8,9,0 };
printf("\n%u\t%u", a+1, &a+1);
}

17. What would be the output of the following program?


#include <stdio.h>
main()
{
char a[ ] = "Visual C++";
char *b = "Visual C++";
printf("\n %d\t%d", sizeof(a), sizeof(b));
printf("\n%d\t%d", sizeof(*a), sizeof(*b));
}

18. For the following statements would arr[3] and ptr[3] fetch the same character? <Yes/No>
char arr[] = "Surprised";
char *ptr = "Surprised";

19. What would be the output of the following program, if the array begins at address 65486?
#include <stdio.h>
main()
{
int arr[] = {12, 14, 15, 23, 45};
printf("%u\t%u", arr, &arr);
}
20. What is the output of the following program.

#include<stdio.h>
main()
{
static int b[] = { 1 0 , 2 0 , 3 0 , 4 0 , 5 0 } ;
int i;
for (i = 0 ; i <= 4 ; i++)
printf ("%d", i[b]);
}

S-ar putea să vă placă și