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

Write a routine to implement the polymarker function

0 Answers   TCS,


Program to Delete an element from a doubly linked list.

4 Answers   College School Exams Tests, Infosys,


main() { int a[10]; printf("%d",*a+1-*a+3); }

1 Answers  


main(){ int a= 0;int b = 20;char x =1;char y =10; if(a,b,x,y) printf("hello"); }

1 Answers   TCS,


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

0 Answers   Student,






main() { signed int bit=512, i=5; for(;i;i--) { printf("%d\n", bit = (bit >> (i - (i -1)))); } } a. 512, 256, 128, 64, 32 b. 256, 128, 64, 32, 16 c. 128, 64, 32, 16, 8 d. 64, 32, 16, 8, 4

2 Answers   HCL,


how to test pierrot divisor

0 Answers  


Write a program that produces these three columns sequence nos. using loop statement Sequence nos. Squared Squared + 5 1 1 6 2 4 9 3 9 14 4 16 21 5 25 30

1 Answers   GoDB,


main() { char *a = "Hello "; char *b = "World"; clrscr(); printf("%s", strcat(a,b)); } a. Hello b. Hello World c. HelloWorld d. None of the above

3 Answers   HCL,


main() { extern int i; { int i=20; { const volatile unsigned i=30; printf("%d",i); } printf("%d",i); } printf("%d",i); } int i;

1 Answers  


void main() { int i=10, j=2; int *ip= &i, *jp = &j; int k = *ip/*jp; printf(“%d”,k); }

1 Answers  


Design an implement of the inputs functions for event mode

0 Answers   Wipro,


Categories