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

Edit

Write in Short

Short Answer▾

What is the output of the following program?

structpoint{intx;inty;};structpointorigin,⚹pp;main(){pp=&origin;printf("origin is(%d%d)",(⚹pp).x,(⚹pp).y);printf("origin is (%d%d)",pp x,pp y);}

Explanation

  • In the program
    Table Shows the Program
    int x; int y;Structure pointer is globally declared with x and y.
    pp = &origin;pp is a pointer to structure.
    printf ( “origin is (% d % d) ” , (⚹ pp) . x, (⚹ pp) . y) ; printf ( “origin is (% d % d) ” , pp ⇾ x, pp ⇾ y) ;We can access the elements ofthe structure either with arrow mark or with indirection operator.

    Since structure point is globally declared x & y are initialized as zeroes

  • So, the answer is origin is (0,0) origin is (0,0) .

Question 199

Languages
Edit

Write in Short

Short Answer▾

When can subclasses not access superclass members?

Explanation

Understanding of Super Class and Sub Class
  • When superclass is declared as private then subclasses cannot access superclass members.
  • The subclass can directly access the public members of the superclass.
  • Subclass can override the public members of the superclass.

Question 200

Edit

Describe in Detail

Essay▾

Predict the output or error (s) for the following:

  1. #include<stdio.h>
  2. main ()
  3. {
  4.     char ⚹str =“hello”;
  5.     char ⚹ptr =str;
  6.     charleast =127;
  7.     while (⚹ptr++)
  8.     least =⚹ptr;
  9.     printf ( “%d”,least);
  10. }

Explanation

In the program

Table Shows the Program
char ⚹ str = “hello” ;
  • Define character pointer str = hello
char ⚹ ptr = str;
  • After ‘ptr’ reches the end of the string the value pointed by ‘str’ is ‘⧵0’ .
char least = 127;
  • Given the character variable least = 127
while (⚹ ptr ++)
  • The value of ‘str’ is less than that of ‘least’
least =⚹ ptr;
  • The value of ‘least’ is store the ⚹ ptr value
printf ( “% d” , least) ;
  • So the value of ‘least’ is 0.

Developed by: