main()

{

char str1[] = {‘s’,’o’,’m’,’e’};

char str2[] = {‘s’,’o’,’m’,’e’,’\0’};

while (strcmp(str1,str2))

printf(“Strings are not equal\n”);

}



main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {..

Answer / susie

Answer :

“Strings are not equal”

“Strings are not equal”

….

Explanation:

If a string constant is initialized explicitly with
characters, ‘\0’ is not appended automatically to the
string. Since str1 doesn’t have null termination, it treats
whatever the values that are in the following positions as
part of the string until it randomly reaches a ‘\0’. So str1
and str2 are not the same, hence the result.

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C Code Interview Questions

char *someFun() { char *temp = “string constant"; return temp; } int main() { puts(someFun()); }

1 Answers  


int i; main(){ int t; for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) printf("%d--",t--); } // If the inputs are 0,1,2,3 find the o/p

2 Answers  


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

3 Answers   Infosys, Made Easy, State Bank Of India SBI,


#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }

1 Answers  


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

0 Answers   United Healthcare, Virtusa,


#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,


main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }

2 Answers   HP,


1. const char *a; 2. char* const a; 3. char const *a; -Differentiate the above declarations.

3 Answers  


main() { struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }

1 Answers  


Which version do you prefer of the following two, 1) printf(“%s”,str); // or the more curt one 2) printf(str);

1 Answers  


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  


void main() { int i; char a[]="\0"; if(printf("%s\n",a)) printf("Ok here \n"); else printf("Forget it\n"); }

3 Answers   Accenture,


Categories