Languages [3i Infotech Placement]: Sample Questions 61 - 62 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 61

Edit

Describe in Detail

Essay▾

Which bit wise operator is suitable for checking whether a particular bit is on or off?

Explanation

Define Logical Operator
  • Operator is suitable for checking weather particular bit is on or off.
  • For example,
  • Suppose in byte has value 10101101.
  • We check whether bit number 3 is ON (1) or OFF (0) .
  • For checking bit number 3, the second operand for AND operation is binary 00001000, which is equal to 8 in decimal.

  • Since the resulting value is 8, that is value of the second operand the bit was ON
  • If the answer was 0, the bit number 3 in the resulting bit pattern would have evaluated 0 and complete bit pattern have 00000000.

Question 62

Edit

Describe in Detail

Essay▾

Find the output for the following C program

  1. main ()
  2. {
  3.     char ⚹p1 =“Name” ;
  4.     char ⚹p2;
  5.     p2 =(char ⚹) malloc(20);
  6.     while ( ⚹p2 ++ =⚹ p1 ++ );
  7.     printf ( “%s”, p2);
  8. }

Explanation

  • In the program
Table Showing the Program
char ⚹ p1 = “Name” ;
  • define the character pointer p1 = “Name”
char ⚹ p2;
  • define the character pointer p2
p2 = (char ⚹) malloc (20) ;
  • using the malloc () function
  • void ⚹ malloc (size_t size) allocates the requested memory and returns a pointer to it.
while (⚹ p2 ++ =⚹ p1 ++) ;
  • apply the while condition
printf ( “% s” , p2) ;
  • printf prints the pointer p2 value
  • pointer p2 has no string so it is empty string

Developed by: