C Programming Questions and Answers:: Const

@ : Home > C Programming Questions and Answers > Const > Find Output of Program

What will be the output of the program?


#include

int main()
{
    const char *s = "";
    char str[] = "Hello";
    s = str;
    while(*s)
        printf("%c", *s++);

    return 0;
}
A. Error
B. H
C Hello
D. Hel

What will be the output of the program?


#include
int get();

int main()
{
    const int x = get();
    printf("%d", x);
    return 0;
}
int get()
{
    return 20;
}
A. Garbage value
B. Error
C 20
D. 0

What will be the output of the program (in Turbo C)?


#include

int fun(int *f)
{
    *f = 10;
    return 0;
}
int main()
{
    const int arr[5] = {1, 2, 3, 4, 5};
    printf("Before modification arr[3] = %d", arr[3]);
    fun(&arr[3]);
    printf("\nAfter modification arr[3] = %d", arr[3]);
    return 0;
}
A. Before modification arr[3] = 4 After modification arr[3] = 10
B. Error: cannot convert parameter 1 from const int * to int *
C Error: Invalid parameter
D. Before modification arr[3] = 4 After modification arr[3] = 4

What will be the output of the program?


#include

int main()
{
    const c = -11;
    const int d = 34;
    printf("%d, %d\n", c, d);
    return 0;
}
A. Error
B. -11, 34
C 11, 34
D. None of these

What will be the output of the program in TurboC?


#include
int fun(int **ptr);

int main()
{
    int i=10, j=20;
    const int *ptr = &i;
    printf(" i = %5X", ptr);
    printf(" ptr = %d", *ptr);
    ptr = &j;
    printf(" j = %5X", ptr);
    printf(" ptr = %d", *ptr);
    return 0;
}
A. i= FFE2 ptr=12 j=FFE4 ptr=24
B. i= FFE4 ptr=10 j=FFE2 ptr=20
C i= FFE0 ptr=20 j=FFE1 ptr=30
D. Garbage value

Page 1 of 3