closepop
closepop

Would you like to submit the test?


C Language :

Const




1.
What will be the output of the program?

#include<stdio.h>

int main()
{
    int y=128;
    const int x=y;
    printf("%dn", x);
    return 0;
}

128
garbage value
error
0




2.
What will be the output of the program?

#include<stdio.h>
#include<stdlib.h>

union employee
{
    char name[15];
    int age;
    float salary;
};
const union employee e1;

int main()
{
    strcpy(e1.name, "K");
    printf("%s %d %f", e1.name, e1.age, e1.salary);
    return 0;
}

Error: RValue required
Error: cannot convert from 'const int *' to 'int *const'
Error: LValue required in strcpy
No error




3.
What will be the output of the program?

#include<stdio.h>
int fun(int **ptr);

int main()
{
    int i=10;
    const int *ptr = &i;
    fun(&ptr);
    return 0;
}
int fun(int **ptr)
{
    int j = 223;
    int *temp = &j;
    printf("Before changing ptr = %5xn", *ptr);
    const *ptr = temp;
    printf("After changing ptr = %5xn", *ptr);
    return 0;
}

Address of i: Address of j
10 , 223
Error: cannot convert parameter 1 from 'const int **' to 'int **'
Garbage value




4.
What will be the output of the program?

#include<stdio.h>

int main()
{
    const int x=5;
    const int *ptrx;
    ptrx = &x;
    *ptrx = 10;
    printf("%dn", x);
    return 0;
}

5
10
error
garbage value




5.
What will be the output of the program in TurboC?

#include<stdio.h>
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;
}

i= FFE2 ptr=12 j=FFE4 ptr=24
i= FFE2 ptr=10 j=FFE4 ptr=20
i= FFE2 ptr=20 j=FFE4 ptr=30
garbage value




6.
What will be the output of the program?

#include<stdio.h>

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

    return 0;
}

error
h
hello
hel




7.
What will be the output of the program?

#include<stdio.h>
int get();

int main()
{
    const int x = get();
    printf("%d", x);
    return 0;
}
int get()
{
    return 20;
}

garbage value
error
20
0




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

#include<stdio.h>

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;
}

Before modification arr[3] = 4 After modification arr[3] = 10
Error: Invalid parameter
both a and b
none of these




9.
What will be the output of the program?

#include<stdio.h>

int main()
{
    const int i=0;
    printf("%dn", i++);
    return 0;
}

10
11
no output
Error: ++needs a value




10.
  What will be the output of the program?

#include

int main()
{
    const c = -11;
    const int d = 34;
    printf("%d, %dn", c, d);
    return 0;
}

error
-11,34
11,34
none of these










FreshersLive - No.1 Job site in India. Here you can find latest 2016 government as well as private job recruitment notifications for different posts vacancies in India. Get top company jobs for both fresher and experienced. Job Seekers can get useful interview tips, resume services & interview Question and answer. Practice online test free which is helpful for interview preparation. Register with us to get latest employment news/rojgar samachar notifications. Also get latest free govt and other sarkari naukri job alerts daily through E-mail.


FreshersLive - No.1 Job site in India. Here you can find latest 2016 government as well as private job recruitment notifications for different posts vacancies in India. Get top company jobs for both fresher and experienced. Job Seekers can get useful interview tips, resume services & interview Question and answer. Practice online test free which is helpful for interview preparation. Register with us to get latest employment news/rojgar samachar notifications. Also get latest free govt and other sarkari naukri job alerts daily through E-mail.