What is the subtle error in the following code segment?

void fun(int n, int arr[])

{

int *p=0;

int i=0;

while(i++<n)

p = &arr[i];

*p = 0;

}



What is the subtle error in the following code segment? void fun(int n, int arr[]) ..

Answer / susie

Answer : & Explanation:

If the body of the loop never executes p is assigned no
address. So p remains NULL where *p =0 may result in problem
(may rise to runtime error “NULL pointer assignment” and
terminate the program).

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C Code Interview Questions

# include <stdio.h> int one_d[]={1,2,3}; main() { int *ptr; ptr=one_d; ptr+=3; printf("%d",*ptr); }

1 Answers  


#include<stdio.h> main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s[3]; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

2 Answers   CNSI,


void main() { int i=5; printf("%d",i+++++i); }

3 Answers  


create a login program that ask username and password. if you input username or password 3 times wrong, the program will terminate else the program will prompt a message "congratulations"

2 Answers  


source code for delete data in array for c

1 Answers   TCS,






void main() { int i=5; printf("%d",i++ + ++i); }

3 Answers  


main() { char *p; int *q; long *r; p=q=r=0; p++; q++; r++; printf("%p...%p...%p",p,q,r); }

1 Answers  


Link list in reverse order.

8 Answers   NetApp,


why is printf("%d %d %d",i++,--i,i--);

4 Answers   Apple, Cynity, TCS,


#include<stdio.h> main() { struct xx { int x; struct yy { char s; struct xx *p; }; struct yy *q; }; }

1 Answers  


#include<stdio.h> main() { struct xx { int x=3; char name[]="hello"; }; struct xx *s=malloc(sizeof(struct xx)); printf("%d",s->x); printf("%s",s->name); }

1 Answers   TCS,


write a c program to Create a registration form application by taking the details like username, address, phone number, email along with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 5 users and display the details. In place of password display “****”. (Use Structures).

0 Answers   CDAC, College School Exams Tests,


Categories