About

Practicing code on codechef. in 3rd year of B.tech. preparing for GATE-2018 . let's make it .

Role

Alma Mater:

B.Tech in information technology
Kamla Nehru Institute of Technology, Sultanpur
2014 to 2018

Experience:

IT fundamentals and Programming language Trainer
NIIT Sultanpur
2015 to 2017
Babytud
Answer
1 year 2 months ago

Answer is (D). sorry for that

 

 

Explanation:

(A) is wrong. We don’t need to cast the result as void * is automatically and safely promoted

to any other pointer type in this case.

 

 

(B) It is discarded for obvious reason.

 

 

 

 

(C) is wrong, because dangling pointer is nothing but the pointer which is pointing

to non-existing memory (deallocated or deleted memory) which is not happening here.

 

 

(D) is the answer. When you are calling malloc second time, new location is assigned to x and previous memory location is lost and now we don’t have no reference to that location resulting in memory leak.

moreless
Babytud
Answer
1 year 2 months ago

compiler error because the comparison should be made as x==NULL and not as shown.

moreless
Babytud
Answer
1 year 2 months ago

Nopes...

> is Relational Operator while >> (called as right shift) is Bitwise operator it works on bits

 

lets take an example;   assume that v=20;

it means in binary it would be    v= 10100;

than,  v>>2; means 10100>>2 ==00101 (two bits shifted towards right in )

in decimal 00101 is 5, so v>>=2; means v becomes 5   (after v=v>>2;)

 

 

 

moreless
Babytud
Answer
1 year 2 months ago

v=v>>1;  // 1001>>1==0100

moreless
sumitverma's picture
Sumit Verma
pritam's picture
Pritam Prasun
905
Kuldip Gusani
36314
6 May 2017 - 4:07pm

Answer is (D). sorry for that

 

 

Explanation:

(A) is wrong. We don’t need to cast the result as void * is automatically and safely promoted

to any other pointer type in this case.

 

 

(B) It is discarded for obvious reason.

 

 

 

 

(C) is wrong, because dangling pointer is nothing but the pointer which is pointing

to non-existing memory (deallocated or deleted memory) which is not happening here.

 

 

(D) is the answer. When you are calling malloc second time, new location is assigned to x and previous memory location is lost and now we don’t have no reference to that location resulting in memory leak.

more less
6 May 2017 - 2:06pm

compiler error because the comparison should be made as x==NULL and not as shown.

more less

Nopes...

> is Relational Operator while >> (called as right shift) is Bitwise operator it works on bits

 

lets take an example;   assume that v=20;

it means in binary it would be    v= 10100;

than,  v>>2; means 10100>>2 ==00101 (two bits shifted towards right in )

in decimal 00101 is 5, so v>>=2; means v becomes 5   (after v=v>>2;)

 

 

 

more less

v=v>>1;  // 1001>>1==0100

more less