- Base address of the array
- Value of elements in array
- First element of the array
Explanation:
When passing an array as a parameter to a function in the C programming language, the base address of the array is what gets transmitted.
2) What will be the output of the below program?
#include<stdio.h>
main()
{
char x[]="javaLogic Practice", y[]="javaLogic Practice";
if(x==y){
printf("Strings are Equal");
}
}
- Strings are Equal
- No output
- Runtime error
- Compilation error
Explanation:
In the program, we are evaluating the base memory location of variables 'x' and 'y' and confirming they are different.
Therefore the program has No output.
3) What will be the output of the below program?
#include<stdio.h>
main(){
char x[] = "Hi\0Hello";
printf("%d %d", strlen(x), sizeof(x));
}
- 9 20
Explanation:
The strlen(x) function is employed to determine the size of the string 'x'. In programming, the string's length is calculated by counting characters until reaching the '\0' null terminator. Consequently, the output for the string length is 2.
The sizeof(x) function determines the length of string 'x'. When used in a program, sizeof provides the total size of the array, resulting in an array size output of 9.
Therefore, the collective result generated by the program is 2 and 9.
4) A pointer to a block of memory is effectively same as an array.
- True
- False
Explanation:
Utilize the malloc standard library function to allocate memory and consider it as an array where the array's value is equivalent to a pointer pointing to a memory block.
Consequently, it is feasible to dynamically allocate a block of memory within an array during runtime.
5) Which of the following statements are correct about array in C?
- The expression num[2] represents the very second element in the array
- The declaration of num[SIZE] is allowed if SIZE is a macro
- The array of int num[20]; can store 20 elements
- It is necessary to initialize array at the time of declaration
Explanation:
Therefore statements '2' and '3' are correct.
- The expression num[2] represents the second element in array. This statement is false, because it represents the third element of the array.
- The declaration of num[SIZE] is allowed if SIZE is a macro. This statement is true, because MACRO is used for replacing the symbol size with given value.
- The array of int num[20]; can store 20 elements. This statement is true
- It is necessary to initialize array at the time of declaration. This statement is false