Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
379 views
in Information Technology by (114k points)
closed by

What will be the output of the following?

#include

int main()

{

int a = 5;

scanf("%d",a);

return 0;

}


1. A
2. 0
3. Abnormal termination of program
4. 5

1 Answer

0 votes
by (115k points)
selected by
 
Best answer
Correct Answer - Option 3 : Abnormal termination of program

Scanf:

  • In C, the scanf feature allows a programmer to accept input from a standard input device (keyboard) and store it in variables.
  • The scanf function is very similar to the printf function.
  • It reads data from the input device rather than printing it on the output device.
  • Each variable must be preceded by the ampersand (&) address-of operator in scanf function.

Example:

1) int a;

   scanf (" %d ", &a);

This will take the integer value and assign it to a, (No error).

2) int a;

   scanf (" %d ", a);

It will gave "Segmentation fault" 

It means accessing an invalid memory location, result in abnormal termination of the program.

Hence the option (3) is correct.

Related questions

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...