Languages [3i Infotech Placement]: Sample Questions 223 - 224 of 546

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

Question 223

Describe in Detail Essay▾

What is the output of the following program?

  1. main ()
  2. {
  3. float f =5, g =10;
  4. enum { i =10, j =20, k =50};
  5. printf ( “%d” ++ k);
  6. printf ( “%f f2);
  7. printf ( “%lf f%g);
  8. printf ( “%lf fmod (f, g) );
  9. }
Edit

Explanation

Line no 5: Error: L value required

Line no 6: Cannot apply leftshift to float

Line no 7: Cannot apply mod to float

In the program

Table Shows the Program
float f = 5, g = 10;
  • Define the floating variable f and g and value is 5 and 10 continue
enum {i = 10, j = 20, k = 50} ;
  • Define the enumeration constants
printf ( “% d” ++ k) ;
  • Enumeration constants cannot be modified, so you cannot apply ++ .
printf ( “% f” f << 2) ;

printf ( “% lf” f % g) ;

  • Bit-wise operators and % operators cannot be applied on float values.
printf ( “% lf” fmod (f, g) ) ;
  • fmod () is to find the modulus values for floats as % operator is for ints.
Lvalues and Rvalues in Image

Question 224

Describe in Detail Essay▾

What is the problem with the following code segment?

While ( (fgets (receiving array, 50, file_ptr) ) ! = EOF) ;

Edit

Explanation

  • fgets returns a string pointer not file pointer (string pointer can be NULL not EOF) . So the correct end of file check is checking for! = NULL.
  • Function char ⚹ fgets (char ⚹ str, int n, FILE ⚹ stream) reads a line from the specified stream and stores it into the string pointed to by str.
  • It stops when (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.

Example:

Example Shows the Usage of Fgets () Function
  • Let us assume, we have a text file file. txt, which has the following content. This file will be used as an input for our example program:

    “We are in 2017”

  • Now, let us compile and run the above program that will produce the following result:

We are in 2017