C Programming - Strings
Exercise : Strings - Yes / No Questions
- Strings - General Questions
- Strings - Find Output of Program
- Strings - Point Out Correct Statements
- Strings - Yes / No Questions
1.
Will the program compile successfully?
#include<stdio.h>
int main()
{
char a[] = "India";
char *p = "BIX";
a = "BIX";
p = "India";
printf("%s %s\n", a, p);
return 0;
}
Answer: Option
Explanation:
Because we can assign a new string to a pointer but not to an array a.
2.
For the following statements will arr[3] and ptr[3] fetch the same character?
char arr[] = "IndiaBIX";
char *ptr = "IndiaBIX";
char arr[] = "IndiaBIX";
char *ptr = "IndiaBIX";
Answer: Option
Explanation:
Yes, both the statements prints the same character 'i'.
3.
Is there any difference between the two statements?
char *ch = "IndiaBIX";
char ch[] = "IndiaBIX";
char *ch = "IndiaBIX";
char ch[] = "IndiaBIX";
Answer: Option
Explanation:
In first statement the character pointer ch stores the address of the string "IndiaBIX".
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.
The second statement specifies the space for 7 characters be allocated and that the name of location is ch.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers