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

Languages
Edit

Write in Short

Short Answer▾

Where are the card layouts used?

Explanation

  • Cardlayout class manages two or more components that share the same display space.
  • Provides a way for user to choose between the components.
  • CardLayout class manages the components in such a manner that only one component is visible at a time. It treats every component in the container as card. One card is visible at a time, and the container acts as stack of cards.

Question 84

Edit

Describe in Detail

Essay▾

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

  1. char ⚹someFun1()
  2. { chartemp[ ] =“string";returntemp; } char ⚹someFun2() { chartemp[ ] ={‘s’, ‘t’,’r’,’i’,’n’,’g’}; returntemp; }intmain()
  3. { puts(someFun1()); puts(someFun2()); }

Explanation

  • In the program both the functions suffer from the problem of dangling pointers
Table Showing the Program
char ⚹ someFun1 ()

{char temp [] = “string” ; return temp;}

  • In someFun1 () temp is a character array
  • The space for it is allocated in heap and is initialized with character string “string” .
  • This is created dynamically as the function is called, so is also deleted dynamically on exiting the function
  • So the string data is not available in the calling function main () leading to printing of garbage values.
char ⚹ someFun2 () {char temp [] = { ‘s’ , ‘t’ , ‘r’ , ‘i’ , ‘n’ , ‘g’ } ; return temp;}
  • The function someFun2 () also suffers from the same problem but the problem can be easily identified in this case.

Developed by: