IndiaBIX
IndiaBIX
Start typing & press "Enter" or "ESC" to close
  • Home
  • Jobs
  • Results
  • Current Affairs
  • GK
  • Online Test
  • HR Interview
  • BLOG

Const (1)

  • Home
  • Computer Science & Engineering
  • C Programming Questions and Answers
  • Const
1. 

What will be the output of the program?

#include<stdio.h>

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

Answer: Option B

Explanation:

Step 1: const c = -11; The constant variable 'c' is declared and initialized to value "-11".

Step 2: const int d = 34; The constant variable 'd' is declared as an integer and initialized to value '34'.

Step 3: printf("%d, %d\n", c, d); The value of the variable 'c' and 'd' are printed.

Hence the output of the program is -11, 34

View Answer Discuss Workspace Report

2. 

What will be the output of the program?

#include<stdio.h>

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

A. 10
B. 11
C. No output
D. Error: ++needs a value

Answer: Option D

Explanation:

This program will show an error "Cannot modify a const object".

Step 1: const int i=0; The constant variable 'i' is declared as an integer and initialized with value of '0'(zero).

Step 2: printf("%d\n", i++); Here the variable 'i' is increemented by 1(one). This will create an error "Cannot modify a const object".

Because, we cannot modify a const variable.

View Answer Discuss Workspace Report

3. 

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

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

Answer: Option A

Explanation:

Step 1: const int arr[5] = {1, 2, 3, 4, 5}; The constant variable arr is declared as an integer array and initialized to

arr[0] = 1, arr[1] = 2, arr[2] = 3, arr[3] = 4, arr[4] = 5

Step 2: printf("Before modification arr[3] = %d", arr[3]); It prints the value of arr[3] (ie. 4).

Step 3: fun(&arr[3]); The memory location of the arr[3] is passed to fun() and arr[3] value is modified to 10.

A const variable can be indirectly modified by a pointer.

Step 4: printf("After modification arr[3] = %d", arr[3]); It prints the value of arr[3] (ie. 10).

Hence the output of the program is

Before modification arr[3] = 4

After modification arr[3] = 10

View Answer Discuss Workspace Report

4. 

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

A. Garbage value
B. Error
C. 20
D. 0

Answer: Option C

Explanation:

Step 1: int get(); This is the function prototype for the funtion get(), it tells the compiler returns an integer value and accept no parameters.

Step 2: const int x = get(); The constant variable x is declared as an integer data type and initialized with the value "20".

The function get() returns the value "20".

Step 3: printf("%d", x); It prints the value of the variable x.

Hence the output of the program is "20".

View Answer Discuss Workspace Report

5. 

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

A. Error
B. H
C. Hello
D. Hel

Answer: Option C

Explanation:

Step 1: const char *s = ""; The constant variable s is declared as an pointer to an array of characters type and initialized with an empty string.

Step 2: char str[] = "Hello"; The variable str is declared as an array of charactrers type and initialized with a string "Hello".

Step 3: s = str; The value of the variable str is assigned to the variable s. Therefore str contains the text "Hello".

Step 4: while(*s){ printf("%c", *s++); } Here the while loop got executed untill the value of the variable s is available and it prints the each character of the variable s.

Hence the output of the program is "Hello".

View Answer Discuss Workspace Report

6. 

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

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

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.
View Answer Discuss Workspace Report

7. 

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("%d\n", x);
return 0;
}

A. 5
B. 10
C. Error
D. Garbage value

Answer: Option C

Explanation:

Step 1: const int x=5; The constant variable x is declared as an integer data type and initialized with value '5'.

Step 2: const int *ptrx; The constant variable ptrx is declared as an integer pointer.

Step 3: ptrx = &x; The address of the constant variable x is assigned to integer pointer variable ptrx.

Step 4: *ptrx = 10; Here we are indirectly trying to change the value of the constant vaiable x. This will result in an error.

To change the value of const variable x we have to use *(int *)&x = 10;

View Answer Discuss Workspace Report

8. 

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 = %5x\n", *ptr);
const *ptr = temp;
printf("After changing ptr = %5x\n", *ptr);
return 0;
}

A. Address of i Address of j
B. 10 223
C. Error: cannot convert parameter 1 from 'const int **' to 'int **'
D. Garbage value

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.
View Answer Discuss Workspace Report

  • 1
  • 2

Questions & Answers

Aptitude Chemical Engineering Civil Engineering Computer Science & Engineering Current Affairs Data Interpretation Electrical & Electronics Engineering Electronics & Communication Engineering General Knowledge Logical Reasoning Mechanical Engineering Non Verbal Reasoning Verbal Ability Verbal Reasoning

Interviews

HR Interview

Jobs

Sarkari Jobs

Results

Rojgar ResultSarkari Result

Admission

Admission 2023

Admit Card

Admit Card 2023

Answer Key

Answer Key 2023
copyright
Privacy Policy
© 2025 IndiaBIX. All Rights Reserved.

Report