main()

{

char a[4]="HELLO";

printf("%s",a);

}

Answers were Sorted based on User's Feedback



main() { char a[4]="HELLO"; printf("%s",a); ..

Answer / dani

Actually I compiled this and ran it unix and it just prints out a warning, not an error:
"warning: initializer-string for array of chars is too long"

The programme prints the initial array without the last character (because of the '\0' special character):
"HELL �"

Is This Answer Correct ?    5 Yes 1 No

main() { char a[4]="HELLO"; printf("%s",a); ..

Answer / smk

too many intializer for a[4](warning)

Is This Answer Correct ?    3 Yes 0 No

main() { char a[4]="HELLO"; printf("%s",a); ..

Answer / susie

Answer :

Compiler error: Too many initializers

Explanation:

The array a is of size 4 but the string constant requires 6
bytes to get stored.

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C Code Interview Questions

main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

2 Answers   CSS, Wipro,


How do you create a really large matrix (i.e. 3500x3500) in C without having the program crash? I can only reach up to 2500. It must have something to do with lack of memory. Please help!

1 Answers  


main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }

9 Answers   CSC, GoDB Tech, IBM,


#include <stdio.h> #define a 10 main() { #define a 50 printf("%d",a); }

2 Answers  


main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }

1 Answers  


#define a 10 void foo() { #undef a #define a 50 } int main() { printf("%d..",a); foo(); printf("%d..",a); return 0; } explain the answer

1 Answers  


main() { char *p; p="%d\n"; p++; p++; printf(p-2,300); }

1 Answers  


x=2 y=3 z=2 x++ + y++; printf("%d%d" x,y);

2 Answers  


Write a routine to implement the polymarker function

0 Answers   TCS,


how to delete an element in an array

2 Answers   IBM,


main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }

1 Answers  


write a simple calculator c program to perform addition, subtraction, mul and div.

0 Answers   United Healthcare, Virtusa,


Categories