Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 165 - 167 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 165

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

1. #defineDIM (array, type) sizeof (array)/sizeof (type)
2. main ()
3. {
4.     intarr;
5.     printf (“Thedimensionofthearrayis %d”, DIM (arr, int) );
6. }

Explanation

The dimension of the array is 10

In the program

 int arr  ; The size of integer array of 10 elements is 10 ⚹ sizeof (int) . #define DIM (array, type) sizeof (array) /sizeof (type) The macro expands to size of (arr) /size of (int) ⩾ 10 ⚹ size of (int) /size of (int) ⩾ 10 printf ( “The dimension of the array is % d” , DIM (arr, int) ) ; Printf prints The dimension of the array as 10.

Question 166

C & C Plus Plus
Edit

Describe in Detail

Essay▾

Write a program which uses command line arguments.

Explanation

1. #include<stdio.h>
2. voidmain(intargc, char ⚹argv[])
3. {
4.     inti, sum =0;
5.     if (argc !=3)
6.     {
7.         printf("You have forgot to type numbers.");
8.         exit(1);
9.     }
10.     printf("The sum is :");
11.     for (i =1; i <argc; i++)
12.     sum =sum +atoi(argv[i]);
13.     printf("%d", sum);
14. }

OUTPUT:

Sum is: 30

Question 167

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is the output of the following program?

1. #defineFALSE-1
2. #defineTRUE1
3. #defineNULL0
4. main ()
5. {
6.     if (NULL)
7.     puts ( “NULL” );
8.     else
9.     if (FALSE)
10.     puts ( “TRUE” );
11.     else
12.     puts ( “FALSE” );
13. }

Explanation

• The input program sent to the compiler after processing by thepreprocessor is, main () {if (0) puts ( “NULL” ) ; else if (-1) puts ( “TRUE” ) ; elseputs ( “FALSE” ) ;}
• Preprocessor does not replace the values given inside thedouble quotes.
 if (NULL)puts ( “NULL” ) ; If condition is boolean false so it goes to else. elseif (FALSE)puts ( “TRUE” ) ; In second if -1 is Boolean value true hence “TRUE” is printed.

Developed by: