C Programming -Initialization of Pointer Arrays

C Programming -Initialization of Pointer Arrays

Question 1
To declare a 3 dimension array using pointers, which of the following is the correct syntax:
A
char *a[][];
B
char **a[];
C
char ***a;
D
All of the mentioned
Question 2
Comment on the output of this C code?
    #include 
    int main()
    {
    char *a = {"p", "r", "o", "g", "r", "a", "m"};
    printf("%s", a);
    }
A
Output will be program
B
Output will be p
C
No output
D
Compile-time error
Question 3
An array of strings can be initialized by:
A
char *a[] = {“Hello”, “World”};
B
char *a[] = {“Hello”, “Worlds”};
C
char *b = “Hello”; char *c = “World”; char *a[] = {b, c};
D
All of the mentioned.
Question 4
What is the output of this C code?
    #include 
    void main()
    {
    char *a[10] = {"hi", "hello", "how"};
    int i = 0;
    for (i = 0;i < 10; i++)
    printf("%s", *(a[i]));
    }
A
Segmentation fault
B
hi hello how followed by 7 null values
C
10 null values
D
depends on compiler
Question 5
What is the output of this C code?
    #include 
    void main()
    {
    char *a[10] = {"hi", "hello", "how"};
    int i = 0, j = 0;
    a[0] = "hey";
    for (i = 0;i < 10; i++)
    printf("%s\n", a[i]);
    }
A
hi hello how Segmentation fault
B
hi hello how followed by 7 null values
C
hey hello how Segmentation fault
D
Depends on compiler
Question 6
What is the output of this C code?
    #include 
    void main()
    {
    char *a[10] = {"hi", "hello", "how"};
    printf("%d\n", sizeof(a));
    }
A
10
B
13
C
Run time error
D
40
Question 7
What is the output of this C code?
    #include 
    void main()
    {
    char *a[10] = {"hi", "hello", "how"};
    printf("%d\n", sizeof(a[1]));
    }
A
6
B
4
C
5
D
3
Question 8
What is the output of this C code?
    #include 
    void main()
    {
    char *a[10] = {"hi", "hello", "how"};
    int i = 0;
    for (i = 0;i < 10; i++)
    printf("%s", a[i]);
    }
A
hi hello how Segmentation fault
B
hi hello how null
C
hey hello how Segmentation fault
D
hi hello how followed by 7 nulls
Question 9
What is the output of this C code?
    #include 
    int main()
    {
    char *p[1] = {"hello"};
    printf("%s", (p)[0]);
    return 0;
    }
A
Compile time error
B
Undefined behaviour
C
hello
D
None of the mentioned
Question 10
What is the output of this C code?
    #include 
    int main()
    {
    char **p = {"hello", "hi", "bye"};
    printf("%s", (p)[0]);
    return 0;
    }
A
Compile time error
B
Undefined behaviour
C
hello
D
Address of hello
Question 11
What is the output of this C code?
    #include 
    int main()
    {
    int i = 0, j = 1;
    int *a[] = {&i, &j};
    printf("%d", (*a)[0]);
    return 0;
    }
A
Compile time error
B
Undefined behaviour
C
0
D
Some garbage value
Question 12
What is the output of this C code?
    #include 
    int main()
    {
    int i = 0, j = 1;
    int *a[] = {&i, &j};
    printf("%d", *a[0]);
    return 0;
    }
A
Compile time error
B
Undefined behaviour
C
0
D
Some garbage value
Question 13
What is the output of this C code?
    #include 
    int main()
    {
    int i = 0, j = 1;
    int *a[] = {&i, &j};
    printf("%d", (*a)[1]);
    return 0;
    }
A
Compile time error
B
Undefined behaviour
C
1
D
Some garbage value
Question 14
Which of the following are generated from char pointer?
A
char *string = “Hello.”;
B
char *string; scanf(“%s”, string);
C
char string[] = “Hello.”;
D
Both (a) and (c).
Question 15
Which of the following declaration are illegal?
A
int a[][] = {{1, 2, 3}, {2, 3, 4, 5}};
B
int *a[] = {{1, 2, 3}, {2, 3, 4, 5}};
C
int a[4][4] = {{1, 2, 3}, {2, 3, 4, 5}};
D
Both (a) and (b).


Check Your Answers:

  1. A
  2. A
  3. D
  4. A
  5. C
  6. D
  7. B
  8. D
  9. C
10. B
11. C
12. C
13. D
14. A
15. A

 
SHARE

Unknown

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment