3i Infotech Placement: Sample Questions 40 - 41 of 1245

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

Question 40

Edit

Write in Short

Short Answer▾

In the command scanf, % h is used for

Explanation

  • Scanf reads data with specified format from a given string stream source.
  • In the command Scanf, % h is used for short int.
  • Example:

int x, y, z, w;

x = scanf ( “% h % d % d” , &y, &z, &w) :

Question 41

Edit

Describe in Detail

Essay▾
  1. voidmain ()
  2. {
  3.     char ⚹s[] ={ "dharma", "hewlett-packard" ,"siemens" ,"ibm" };
  4.     char ⚹⚹p;
  5.     p =s;
  6.     printf("%s ",++⚹p);
  7.     printf("%s ",⚹p++);
  8.     printf("%s ",++⚹p);
  9. }

Explanation

  • The program uses pointer to pointer
  • The first pointer is using to store the address of second pointer. That is why they are known as double pointers.
Concept of Double Pointer
Table Showing the Program
char ⚹ s [] = { “dharma” , “hewlett-packard” , “siemens” , “ibm” } ;
  • Define the pointer array
char ⚹⚹ p;
  • Define the character pointer to pointer p
p = s;
  • Pointer stores the array value
printf ( “% s” , ++ ⚹ p) ;
  • Here printf print the incremented pointer value
  • Here apply (++ ⚹ p) - p thus points to harma from dharma
printf ( “% s” , ⚹ p ++) ;
  • Here printf prints the pointer value
  • Here apply (⚹ p ++) . The increment moves to next char array so p now points to hewlett-packard
printf ( “% s” , ++ ⚹ p) ;
  • Again ++ ⚹ p makes “p” point to ewlett-packard

Developed by: