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

C & C Plus Plus
Edit

Write in Short

Short Answer▾

How would you use the functions fseek () , fread () , fwrite () and ftell () ?

Explanation

  • fseek (f, 1, i) : Move the pointer for file f a distance 1 byte from location i.
  • fread (s, i1, i2, f) : Enter i2 dataitems, each of size i1 bytes, from file f to string s.
  • fwrite (s, i1, i2, f) : Send i2 data items, each of size i1 bytes from string s to file f.
  • ftell (f) : Return the current pointer position within file f.

Question 189

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. #include<stdio.h>
  2. voidmain ()
  3. {
  4.     char ⚹p ="ayqm";
  5.     printf ("%c",⚹(p++));
  6. }

Explanation

In the program

Table Shows the Program
char ⚹ p = “ayqm” ;
  • p is char pointer that stores the address of string “ayqm”
  • Means p has the address of ‘a’ .
printf ( “% c” , ⚹ (++ p) ) ;
  • Outputs ‘a’ .
  • Now ⚹ (p ++) is post-increment that means it prints the value than increment the address by 1.
  • so ⚹ (p ++) prints the value ‘a’ .

Question 190

C & C Plus Plus
Edit

Describe in Detail

Essay▾
  1. main ()
  2. {
  3.     char ⚹p;
  4.     p =“Hello” ;
  5.     printf( “%c” ⚹& ⚹p);
  6. }

Explanation

  • In a program ⚹ is a deference operator.
  • & is a reference operator.
  • They can be applied any number of times provided it is meaningful.
Table Shows the Program
char ⚹ p;Given character pointer p
p = “Hello” ;Assign p = “hello” string
printf ( “% c” ⚹ & ⚹ p) ;Here p points to the first character in the string “hello” .

⚹ p dereferences it and so its value is H.

Again & references it to an address and ⚹ dereferences it to the value H.

Developed by: