All India Exams
Home AptitudeBankEngineeringEnglishGKInterviewOnline TestPlacement PapersReasoning
  • Home
  • Aptitude
  • Bank
  • Engineering
  • English
  • GK
  • Interview
  • Online Test
  • Placement Papers
  • Reasoning

Declarations C Questions And Answers

Here you can find Declarations C Questions and Answers.

Why Declarations C Questions and Answers Required?

In this Declarations C Questions and Answers section you can learn and practice Declarations C Questions and Answers to improve your skills in order to face technical inerview conducted by Banks. By Practicing these interview questions, you can easily crack any Bank Exams interview.

Where can I get Declarations C Questions and Answers?

AllIndiaExams provides you lots Declarations C Questions and Answers with proper explanation. Fully solved examples with detailed answer description. All students, freshers can download Declarations C Questions and Answers as PDF files and eBooks.

How to solve these Declarations C Questions and Answers?

You no need to worry, we have given lots of Declarations C Questions and Answers and also we have provided lots of FAQ's to quickly answer the questions in the Bank Exams interview.

Declarations C Questions and Answers

1. What is the output of this C code? void foo(const int *); int main() { const int i = 10; printf("%d ", i); foo(&i); printf("%d", i); } void foo(const int *i) { *i = 20; }

Declarations C Questions and Answers

2. Comment on the output of this C code? int main() { const int i = 10; int *ptr = &i; *ptr = 20; printf("%d\n", i); return 0; }

Declarations C Questions and Answers

3. What is the output of this C code? int main() { j = 10; printf("%d\n", j++); return 0; }

Declarations C Questions and Answers

4. Does this compile without error? int main() { for (int k = 0; k < 10; k++); return 0; }

Declarations C Questions and Answers

5. Does this compile without error? int main() { int k; { int k; for (k = 0; k < 10; k++); } }

Declarations C Questions and Answers

6. Which of the following declaration is not supported by C?

Declarations C Questions and Answers

7. Which of the following format identifier can never be used for the variable var? int main() { char *var = "Advanced Training in C by AllIndiaExams.com"; }

Declarations C Questions and Answers

8. Which of the following declaration is illegal?

Declarations C Questions and Answers

9. Which keyword is used to prevent any changes in the variable within a C program?

Declarations C Questions and Answers

10. Which of the following is not a pointer declaration?

Home EngineeringComputer Science & EngineeringC Multiple Choice Questions & AnswersDeclarations

Declarations - C Multiple Choice Questions and Answers

This is the c programming questions and answers section on "Declarations and Initializations" with explanation for various interview, competitive examination and entrance test.

Declarations C Questions

Online Test Name Declarations
Exam Type Multiple Choice Questions
Category Computer Science Engineering Quiz
Number of Questions 14
1. What is the output of this C code?

void foo(const int *);
int main()
{
const int i = 10;
printf("%d ", i);
foo(&i);
printf("%d", i);
}
void foo(const int *i)
{
*i = 20;
}
  • A. Compile time error
  • B. 10    20
  • C. Undefined value
  • D. 10
  • View Answer
  • Workspace
  • Report
  • Discuss

Answer & Explanation

Answer: Option A

Explanation:

Cannot change a const type value.
Output:
$ cc pgm1.c
pgm1.c: In function 'foo':
pgm1.c:13: error: assignment of read-only location '*i'

Workspace

Report Error


2. Comment on the output of this C code?

int main()
{
const int i = 10;
int *ptr = &i;
*ptr = 20;
printf("%d\n", i);
return 0;
}
  • A. Compile time error
  • B. Compile time warning and printf displays 20
  • C. Undefined behaviour
  • D. 10
  • View Answer
  • Workspace
  • Report
  • Discuss

Answer & Explanation

Answer: Option B

Explanation:

Changing const variable through non-constant pointers invokes compiler warning
Output:
$ cc pgm2.c
pgm2.c: In function 'main':
pgm2.c:5: warning: initialization discards qualifiers from pointer target type
$ a.out
20

Workspace

Report Error


3. What is the output of this C code?

int main()
{
j = 10;
printf("%d\n", j++);
return 0;
}
  • A. 10
  • B. 11
  • C. Compile time error
  • D. 0
  • View Answer
  • Workspace
  • Report
  • Discuss

Answer & Explanation

Answer: Option C

Explanation:

Variable j is not defined.
Output:
$ cc pgm3.c
pgm3.c: In function 'main':
pgm3.c:4: error: 'j' undeclared (first use in this function)
pgm3.c:4: error: (Each undeclared identifier is reported only once
pgm3.c:4: error: for each function it appears in.)

Workspace

Report Error


4. Does this compile without error?

int main()
{
for (int k = 0; k < 10; k++);
return 0;
}
  • A. Yes
  • B. No
  • C. Depends on the C standard implemented by compilers
  • D. None of the mentioned
  • View Answer
  • Workspace
  • Report
  • Discuss

Answer & Explanation

Answer: Option C

Explanation:

Compilers implementing C90 does not allow this but compilers implementing C99 allow it.
Output:
$ cc pgm4.c
pgm4.c: In function 'main':
pgm4.c:4: error: 'for' loop initial declarations are only allowed in C99 mode
pgm4.c:4: note: use option -std=c99 or -std=gnu99 to compile your code

Workspace

Report Error


5. Does this compile without error?

int main()
{
int k;
{
int k;
for (k = 0; k < 10; k++);
}
}
  • A. Yes
  • B. No
  • C. Depends on the compiler
  • D. Depends on the C standard implemented by compilers
  • View Answer
  • Workspace
  • Report
  • Discuss

Answer & Explanation

Answer: Option A

Explanation:

There can be blocks inside block and within blocks variables have only block scope.
Output:
$ cc pgm5.c

Workspace

Report Error


  • «
  • 1
  • 2
  • 3
  • »

Related Topics:

  • Structures, Unions, Bit-fields
  • C Data Types
  • C Functions
  • Conditional Expressions
  • Data Types
  • Constants
  • Control Flow Statements
  • File Access
  • Preprocessor
  • Pointers

Mock Tests & Online Quizzes

  • Aptitude Online Test

  • Reasoning Online Test

  • GK Online Test

  • English Online Test

  • RRB Mock Test

  • RBI Mock Test

  • Free SBI Mock Test

  • IBPS Mock Test FREE

  • SSC Mock Test

  • CAT Exam Mock Test

  • GATE Mock Test

  • IT Courses Quiz

Questions and Answers

  • Aptitude Questions
  • Verbal Reasoning Questions
  • Non Verbal Reasoning
  • Logical Reasoning Questions
  • Data Sufficiency Questions
  • Data Interpretation
  • eLitmus Sample Papers
  • ECE Questions and Answers
  • EEE Questions and Answers
  • Verbal Ability Questions
  • GK Questions

Programming Quiz

  • C Programming
  • C++ Programming
  • PHP Programming
  • Java Programming
  • Python Programming
  • DataScience MCQ
  • Hadoop MCQ
  • Mongo DB MCQ
  • MySQL MCQ

Interview Questions

  • Java Interview Questions
  • .Net Interview Questions
  • Networking Interview Questions
  • C Language Interview Questions
  • C++ Interview Questions
  • Testing Interview Questions
  • Android Interview Questions
  • HR Interview Questions
  • Group Discussion Topics

Mock Tests

  • CAT Mock Test
  • SSC Mock Test
  • AMCAT Mock Online Test
  • LIC Mock Test
  • IBPS Mock Test
  • RRB Mock Test
  • RBI Mock Test
  • Free SBI Mock Test
© by AllIndiaExams.in. All Rights Reserved | Copyright | Terms of Use & Privacy Policy