...
Question 8421 – Algorithms
December 16, 2023
Question 13826 – Mathematical-Reasoning
December 17, 2023
Question 8421 – Algorithms
December 16, 2023
Question 13826 – Mathematical-Reasoning
December 17, 2023

Question 9781 – Data-Structures

Consider the following three C functions:

[PI]            int*g(void) 
             { 
                int x = 10; 
                return(&x); 
             }  
    
[P2]            int*g(void) 
             { 
                int*px; 
                *px = 10; 
                return px; 
             } 
    
[P3]            int*g(void) 
             { 
                int*px; 
                px = (int *) malloc(sizeof(int)); 
                *px = 10; 
                return px; 
             } 

Which of the above three functions are likely to cause problems with pointers?

Correct Answer: C

Question 38 Explanation: 
[P1] → May cause error because the function is returning the address of locally declared variable.
[P2] → It will cause problem because px is in int pointer that is not assigned with any address and we are doing dereferencing.
[P3] → It will work because memory will be stored in px that can be use further. Once function execution completes this will exist in Heap.
A
Only P3
B
Only P1 and P3
C
Only P1 and P2
D
P1, P2 and P3
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!