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

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What is output for the following program?

  1. #include
  2. main ()
  3. {
  4.     unsignedcharc[] ={ 0 × 1, 0 × 2, 0 × 3, 0 × 4, 0 × 11, 0 × 22, 0 × 33, 0 × 44};
  5.     unsignedint ⚹p =c;
  6.     unsignedshort ⚹s =c;
  7.     printf ( “%x %x %x” c[2], p[2], s[2]);
  8. }

Explanation

Table Showing the Program
#includeStandard library function
main ()startup after initialization
unsigned char c [] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,12, 13] ;Declare unsigned char [8] ,
unsigned int ⚹ p = c;Declare unsigned integer pointer to character p which points to beginning of array c [] .
unsigned short ⚹ s = c;Declare unsigned short pointer s which also points to beginning of c
printf ( “% x % x % x” c [2] , p [2] , s [2] ) ;
  • Note that s is pointer of short which is 2 bytes, int is 4 bytes, char is 1 byte.
  • c [2] will get the third element which is 3
  • p [2] will get to bytes location in the array which is 13
  • s [2] will get to byte location in the array which is 7.
Table Showing the Program
TypeStorage sizeValue range
char1 byte-128 to 127 or 0 to 255
unsigned char1 byte0 to 255
signed char1 byte-128 to 127
int2 or 4 bytes-32,768 to 32,767 or -2, 147,483, 648 to 2, 147,483, 647
unsigned int2 or 4 bytes0 to 65,535 or 0 to 4, 294,967, 295
short2 bytes-32,768 to 32,767
unsigned short2 bytes0 to 65,535
long4 bytes-2, 147,483, 648 to 2, 147,483, 647
unsigned long4 bytes0 to 4, 294,967, 295

Developed by: