Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 338 - 339 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 338

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

1. main ()
2. {
3.     structstudent
4.     {
5.         charname;
6.         structdatedob;
7.     }stud;
8.     structdate
9.     {
10.         intday, month, year;
11.     };
12.     scanf ( “%s%d%d%d” ,stud. Rollno, &student. Dob. Day, &student. Dob. Month, &student. Dob. Year);
13. }

Explanation

Compiler Error: Undefined structure “date”

In the program

 struct student{char name  ;struct date dob;} stud; Inside the struct definition of ‘student’ the member of type struct date is given.The compiler doesn՚t have the definition of date structure (forward reference is not allowed in C in this case)So, it issues an error

Question 339

C & C Plus Plus
Edit

Describe in Detail

Essay▾

For the following C program

1. #defineAREA (x) (3.14 ⚹x ⚹x)
2. main ()
3. {
4.     floatr1 =6.25, r2 =2.5, a;
5.     a =AREA (r1);
6.     printf ( “Areaofthecircleis %f”, a);
7.     a =AREA (r2);
8.     printf ( “Areaofthecircleis %f” ,a);
9. }

What is the output?

Explanation

• In the program
 #define AREA (x) (3.14 ⚹ x ⚹ x) Define the area () function float r1 = 6.25, r2 = 2.5, a; Define the float variable r1 = 6.25, r2 = 2.5 and a variable a = AREA (r1) ; Thus when the preprocessor runs,Here a = AREA (6.25) ;a = (3.14 ⚹ 6.25 ⚹ 6.25)a = 122.656250 printf ( “Area of the circle is % f” , a) ; Printf prints the area of the circle as 122.656250 a = AREA (r2) ; Similarly, a = AREA (2.5) ;a = (3.14 ⚹ 2.5 ⚹ 2.5)a = 19.625000 printf ( “Area of the circle is % f” , a) ; Printf print the Area of the circle is 19.625000

Developed by: