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

Edit

Write in Short

Short Answer▾

What is the output of the following program?

  1. voidmain ()
  2. {
  3.     staticinti =i ++, j =j ++, k =k ++;
  4.     printf (i =%dj =%dk =%d, i, j, k);
  5. }

Explanation

In the program

Table Shows the Program
static int i = i ++ , j = j ++ , k = k ++ ;Here given the static integer variable i, j and k.

Since static variables are initialized to zero by default.

Then the all variables post increment of i, j and k are 1

printf (i =% d j =% d k =% d, i, j, k) ;Printf prints the value of i = 1 , j = 1 and k = 1

Question 193

Question

MCQ▾

Memory allocation of variables declared in a program is

Choices

Choice (4)

a.

allocated in RAM.

b.

allocated in ROM.

c.

assigned to registers.

d.

allocated on stack.

Answer

d.

Explanation

Memory Allocation
  • Variables declared in a program are allocated on the stack.
  • In a stack data is added or removed in a last in first out manner.
  • If a region of memory lies on the thread՚s stack, that memory is said to have been allocated on the stack.
  • Stack-based memory allocation is very simple and typically faster than heap-based memory allocation.
  • Memory on heap is allocated dynamically by the program.
  • Stack based allocation is suitable for temporary data or data which is no longer required after the creating function exits.

Developed by: