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

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

1 Answers  


main(){ unsigned int i; for(i=1;i>-2;i--) printf("c aptitude"); }

2 Answers  


void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }

1 Answers  


Derive expression for converting RGB color parameters to HSV values

1 Answers  


#include <stdio.h> int main(void) { int a=4, b=2; a=b<<a+b>>2 ; printf("%d",a); return 0; }

0 Answers   Student,


typedef struct error{int warning, error, exception;}error; main() { error g1; g1.error =1; printf("%d",g1.error); }

1 Answers  


Give a oneline C expression to test whether a number is a power of 2?

25 Answers   EA Electronic Arts, Google, Motorola,


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

3 Answers   Hexaware,


Write a function to find the depth of a binary tree.

13 Answers   Adobe, Amazon, EFI, Imagination Technologies,


what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); }

3 Answers   Wipro,


Finding a number which was log of base 2

1 Answers   NetApp,


How to use power function under linux environment.eg : for(i=1;i<=n;i++){ pow(-1,i-1)} since it alerts undefined reference to 'pow'.

2 Answers  


Categories