LakshyaEducation.in

VEDIC MATHS Video Series
  • Home
  • Video Series
    • Vedic Maths Videos
    • Quantitative Aptitude Videos
    • Class 8 Maths Videos
    • Class 9 Maths Videos
    • Class 10 Maths Videos
  • Quiz & Solutions
  • Blog
  • Store
  • Login
  • Contact Us
  • Home
  • Topic
  • C Programming
  • Const

C Programming

CONST MCQs

Total Questions : 16

Page 1 of 2 pages
Question 1.


Point out the error in the program.



#include<stdio.h>
const char *fun();

int main()
{
*fun() = 'A';
return 0;
}
const char *fun()
{
return "Hello";
}

  1.    Error: RValue required
  2.    Error: Lvalue required
  3.    Error: fun() returns a pointer const character which cannot be modified
  4.    No error
 Discuss Question
Answer is Option C. -> Error: fun() returns a pointer const character which cannot be modified

Question 2.


Point out the error in the program.



#include<stdio.h>

int main()
{
const int k=7;
int *const q=&k;
printf("%d", *q);
return 0;
}

  1.    Error: RValue required
  2.    Error: Lvalue required
  3.    Error: cannot CONVERT from 'const int *' to 'int *const'
  4.    No error
 Discuss Question
Answer is Option D. -> No error

No error. This will produce 7 as output.

Question 3.


Point out the error in the program.



#include<stdio.h>
int main()
{
const int x;
x=128;
printf("%d\n", x);
return 0;
}

  1.    Error: unknown data type const int
  2.    Error: const variable have been initialised when declared.
  3.    Error: stack overflow in x
  4.    No error
 Discuss Question
Answer is Option B. -> Error: const variable have been initialised when declared.

A const variable has to be initialized when it is declared. later assigning the value to the const 

variable will result in an error "Cannot modify the const object".

Hence Option B is correct

Question 4.


Point out the error in the program.



#include<stdio.h>
const char *fun();

int main()
{
char *ptr = fun();
return 0;
}
const char *fun()
{
return "Hello";
}



  1.    Error: Lvalue required
  2.    Error: cannot convert 'const char *' to 'char *'
  3.    No error and No output
  4.    None of above
 Discuss Question
Answer is Option C. -> No error and No output

Question 5.


Point out the error in 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", e1.name);
e1.age=85;
printf("%d", e1.age);
printf("%f", e1.salary);
return 0;
}

  1.    Error: RValue required
  2.    Error: cannot modify const object
  3.    Error: LValue required in strcpy
  4.    No error
 Discuss Question
Answer is Option B. -> Error: cannot modify const object

Question 6.


Point out the error in the program (in Turbo-C).



#include<stdio.h>
#define MAX 128

int main()
{
const int max=128;
char array[max];
char string[MAX];
array[0] = string[0] = 'A';
printf("%c %c\n", array[0], string[0]);
return 0;
}



  1.    Error: unknown max in declaration/Constant expression required
  2.    Error: invalid array string
  3.    None of above
  4.    No error. It prints A A
 Discuss Question
Answer is Option A. -> Error: unknown max in declaration/Constant expression required

Step 1: A macro named MAX is defined with value 128

Step 2: const int max=128; The constant variable max is declared as an integer data type and it is 

initialized with value 128.

Step 3: char array[max]; This statement reports an error "constant expression required". Because, 

we cannot use variable to define the size of array.

To avoid this error, we have to declare the size of an array as static. Eg. char array[10];or use macro 

char array[MAX];

Note: The above program will print A A as output in Unix platform.

Question 7.


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


  1.    Error
  2.    -11, 34
  3.    11, 34
  4.    None of these
 Discuss Question
Answer is Option B. -> -11, 34

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, %dn", c, d); The value of the variable 'c' and 'd' are printed.

Hence the output of the program is -11, 34

Question 8.


What will be the output of the program?



#include<stdio.h>

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

  1.    10
  2.    11
  3.    No output
  4.    Error: ++needs a value
 Discuss Question
Answer is Option D. -> Error: ++needs a value

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("%dn", 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.

Question 9.


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

  1.    10
  2.    11
  3.    No output
  4.    Error: ++needs a value
 Discuss Question
Answer is Option D. -> Error: ++needs a value

Answer: Option A

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


Question 10.


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


  1.    Garbage value
  2.    Error
  3.    20
  4.    0
 Discuss Question
Answer is Option C. -> 20

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".

  • 1
  • 2
  • Next →
  • Share on Facebook!
  • Share on Pinterest!

Sub Topics

  • Arrays
  • Bitwise Operators
  • C Preprocessor
  • Command Line Arguments
  • Complicated Declarations
  • Const
  • Control Instructions
  • Declarations And Initializations
  • Expressions
  • Floating Point Issues
  • Functions
  • Input / Output
  • Library Functions
  • Memory Allocation
  • Pointers
  • Strings
  • Structures
  • Subleties Of Typedef
  • Variable Number Of Arguments

Topics

  • Computer Aptitude
  • SAIL Junior Officer (E-0)
  • 10th Grade
  • 11th Grade
  • 12th Grade
  • 4th Grade
  • 5th Grade
  • 6th Grade
  • 7th Grade
  • 8th Grade
  • 9th Grade
  • NCERT
  • Cat
  • Commerce
  • Computer Science
  • Engineering
  • English
  • General Knowledge
  • Ias
  • Management
  • Quantitative Aptitude
  • Reasoning Aptitude
  • General Studies (Finance And Economics)
  • Analytical Instrumentation
  • Biochemistry
  • Bioinformatics
  • Biology
  • Biotechnology
  • Bitsat
  • Business Statistics
  • C Programming
  • C++ Programming
  • Cell Biology
  • Chemistry
  • Cost Accounting
  • Drug And Pharmaceutical Biotechnology
  • Electrical Measurement And Instrumentation
  • Environment Management
  • Environmental Biotechnology
  • Enzyme Technology
  • Financial Management And Financial Markets
  • Gate
  • General Science
  • Geography
  • Heat Transfer
  • History And National Movements
  • Human Anatomy And Physiology
  • Human And Cultural Diversity
  • Human Resource Management
  • Indian Economy
  • Indian Geography
  • Indian History
  • Indian Polity
  • Instrumentation Transducers
  • International Relations
  • Life Sciences
  • Marketing And Marketing Management
  • Mass Transfer
  • Mechanics Of Materials
  • Microbiology
  • Neet
  • Professional Communication
  • Renewable Energy
  • Sociology
  • Surveying
  • Total Quality Management
  • Uidai Aadhaar Supervisor Certification
  • Virology

Recent Questions

Q.   In Each Question, The First And The Last Sentences Of The Pa....

Q.   His Death Is A Great Blow, Most Terrible To . . . . . . . .

Q.   Azure Blob Storage Offers How Many Storage Tiers?

Q.   Find Out Whether There Is Any Grammatical Error In Below Sen....

Q.   In Power Point, This Is A Container For Text Or Graphics.

Q.   Symmetric Multiprocessing (SMP) Architectures Are Useful For....

Q.   It Is An Instrument That Entitles The Holder To A Proportio....

Q.   In Each Question Below A Sentence Broken Into Four Or Five P....

Q.   The Playground Of Lawn Tennis Is Called

Q.   How Many Numbers (N) Can We Have, Such That 100<N<1000....

Q.    a Button That Makes Characters Either Upper Or Lower Case ....

Q.    the Area Of A Rectangle Is 45 Cm². If Its Length Is 9 Cm,....

Q.   Which Of The Following Presentation Elements Can You Modify ....

Q.   Di....

Q.   Adversity

Q.   1 U = _______ Nanokatals.

Q.   The Manner In Which Bombs Exploded In Five Trains With In A ....

Q.   Spiny Seeds With Hooks are Dispersed By Animals.

Q.   The Process Of Improving The Cutting Action Of The Grinding ....

Q.   To Meet The Educational Needs Of The People, The Madarasa-I ....

LakshyaEducation.in
Lakshya Education
Bhilai,Chattisgarh,India
Email: admin@lakshyaeducation.in Phone: 07893519977 (WhatsApp)

Quick Links

  • Vedic Maths
  • Quantitative Aptitude
  • Class – IX Maths
  • Class – X Maths
  • YouTube Channel
  • Maths Fast Trick
  • Blog

Our Services

  • About us
  • Privacy
  • TOS
  • Refund / Cancellation
  • Contact
  • Affiliate Program
  • Copyright © 2022 All Right Reserved | Lakshya Education     ( )
    Login / Register

    Your Account will be created automatically when you click the below Google or Facebook Login Button.
    •   Login With Facebook
    •  Login With Google
     Login With Email/Password