Languages-C & C Plus Plus [TCS Placement]: Sample Questions 51 - 52 of 119

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 51

C & C Plus Plus

Write in Short

Short Answer▾

Can I use “int” data type to store the value 32768? Why?


  • No. “Int” data type is capable of storing values from -32768 to 32767.
  • 32768 can be used as “long int” instead.
  • “unsigned int” can also be used if negative values are not to be used.
  • C compiler will not throw any error when 32768 is assigned to an integer type variable. But the actual value in that integer type variable will be -32768.
  • In C programming language the range or size of integer data type is circular- a value greater than 32767, is automatically converted to next value that՚s, -32768.
  • A value less than -32768 is automatically converted to the next value: 32767.

Question 52

C & C Plus Plus

Describe in Detail


What is the use of a ‘⧵0’ character?


  • ‘⧵0’ is terminating null character primarily used to denote the end of a string value.
  • A null-terminated string is a character string stored as an array containing the characters terminated with a null character
  • ‘⧵0’ indicates the end of the array. Hence, this can be used in applications like array traversal to stop traversing when end of the array is reached.
  • In C, a string of characters is stored in successive elements of a character array terminated by the NULL character. For example, the string “Hello” is stored in a character array, msg [] , as follows:

char msg [SIZE] ;

msg [0] = ‘H’ ;

msg [1] = ‘e’ ;

msg [2] = ‘l’ ;

msg [3] = ‘l’ ;

msg [4] = ‘o’ ;

msg [5] = ‘⧵0’ ;

  • The NULL character is written using the escape sequence ‘0’ . The ASCII value of NULL is 0, and NULL is defined as a macro to be 0 in stdio. h- programs can use the symbol, NULL, in expressions if the header file is included.
  • The remaining elements in the array after the NULL may have any garbage values.
  • When the string is retrieved, it will be retrieved starting at index 0 and successive characters are obtained by incrementing the index until the first NULL character is reached signaling the end of the string.

Developed by: