GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Quiz

Quiz on Pointers - Part I

dd_4167 9 Fragen

Quiz starten

Fragen in diesem Quiz (9)

  1. 1What is the output of following program?
    # include <stdio.h>
    void fun(int x)
    {
    x = 30;
    }

    int main()
    {
    int y = 20;
    fun(y);
    printf("%d", y);
    return 0;
    }
    1. A30
    2. B20
    3. CError
  2. 2Output of following program?
    # include <stdio.h>
    void fun(int *ptr)
    {
    *ptr = 30;
    }

    int main()
    {
    int y = 20;
    fun(&y);
    printf("%d", y);

    return 0;
    }
    1. A20
    2. B30
    3. CError
  3. 3Output of following program?
    #include <stdio.h>

    int main()
    {
    int *ptr;
    int x;

    ptr = &x;
    *ptr = 0;

    printf(" x = %d\n", x);
    printf(" *ptr = %d\n", *ptr);

    *ptr += 5;
    printf(" x = %d\n", x);
    printf(" *ptr = %d\n", *ptr);

    (*ptr)++;
    printf(" x = %d\n", x);
    printf(" *ptr = %d\n", *ptr);

    return 0;
    }
    1. Ax = 0
      *ptr = 0
      x = 5
      *ptr = 5
      x = 6
      *ptr = 6
    2. Bx = garbage value
      *ptr = 0
      x = garbage value
      *ptr = 5
      x = garbage value
      *ptr = 6
    3. Cx = 0
      *ptr = 0
      x = 5
      *ptr = 5
      x = garbage value
      *ptr = garbage value
  4. 4Consider a compiler where int takes 4 bytes, char takes 1 byte and pointer takes 4 bytes.
    #include <stdio.h>

    int main()
    {
    int arri[] = {1, 2 ,3};
    int *ptri = arri;

    char arrc[] = {1, 2 ,3};
    char *ptrc = arrc;

    printf("sizeof arri[] = %d ", sizeof(arri));
    printf("sizeof ptri = %d ", sizeof(ptri));

    printf("sizeof arrc[] = %d ", sizeof(arrc));
    printf("sizeof ptrc = %d ", sizeof(ptrc));

    return 0;
    }
    1. Asizeof arri[] = 3 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 4
    2. Bsizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 1
    3. Csizeof arri[] = 12 sizeof ptri = 4 sizeof arrc[] = 3 sizeof ptrc = 4
  5. 5Assume that float takes 4 bytes, predict the output of following program.
    #include <stdio.h>

    int main()
    {
    float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
    float *ptr1 = &arr[0];
    float *ptr2 = ptr1 + 3;

    printf("%f ", *ptr2);
    printf("%d", ptr2 - ptr1);

    return 0;
    }
    1. A90.500000 3
    2. B90.500000 12
    3. C10.000000 12
  6. 6#include<stdio.h>
    int main()
    {
    int arr[] = {10, 20, 30, 40, 50, 60};
    int *ptr1 = arr;
    int *ptr2 = arr + 5;
    printf("Number of elements between two pointer are: %d.",
    (ptr2 - ptr1));
    printf("Number of bytes between two pointers are: %d",
    (char*)ptr2 - (char*) ptr1);
    return 0;
    }
    1. ANumber of elements between two pointer are: 5. Number of bytes between two pointers are: 20
    2. BNumber of elements between two pointer are: 20. Number of bytes between two pointers are: 20
    3. CNumber of elements between two pointer are: 5. Number of bytes between two pointers are: 5
  7. 7#include<stdio.h>
    int main()
    {
    int a;
    char *x;
    x = (char *) &a;
    a = 512;
    x[0] = 1;
    x[1] = 2;
    printf("%d\n",a);
    return 0;
    }
    1. AMachine dependent
    2. B513
    3. C258
  8. 8int main()
    {
    char *ptr = "GeeksQuiz";
    printf("%c\n", *&*&*ptr);
    return 0;
    }
    1. AGarbage Value
    2. BRuntime Error
    3. CG
  9. 9#include<stdio.h>
    void f(int *p, int *q)
    {
    p = q;
    *p = 2;
    }
    int i = 0, j = 1;
    int main()
    {
    f(&i, &j);
    printf("%d %d \n", i, j);
    getchar();
    return 0;
    }
    1. A2 2
    2. B0 1
    3. C0 2

Informationen

Beschreibung
A Quiz on Pointer Concept
Autor
dd_4167
Sprache
English
Aufrufe
198
Bewertung
Noch keine Bewertungen
Bewerte dieses Quiz
Bewerte dieses Quiz

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck