Question: 4. In the following code, the first printf() reached produces the output 14, but the second printf() can cause a bus error or a

4. In the following code, the first printf() reached produces the output 14, but the second printf() can

4. In the following code, the first printf() reached produces the output 14, but the second printf() can cause a bus error or a segmentation fault. Why? main () { int *p; funct (p); printf("%d ", *p); } funct(int *p2) { p2=(int *) malloc (4); *p2=14; printf("%d ", *p2); }

Step by Step Solution

3.46 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code snippet you provided is an example of improper use of pointers in the C programming language which can lead to undefined behavior including b... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!