3,520 views

3 Answers

Best answer
13 13 votes
char *a = "hello world";
printf(a);

char a[] = "hello world";
printf(a);

Both are valid. In first case, programmer is not supposed to modify the contents being pointed to by a as "hello world" is a string literal. In second case, "hello world" is copied to an array a, in the function call space and hence can be modified by the programmer. For printf case, both works the same.

PS: The first argument to printf must be a character pointer and all its characters are printed with format specifiers taken care of separately. So, we do not need %s if we want to just print a string. Avoiding it is actually better for performance reason.

• edited by
0 0 votes
option (a) is correct

because pointer and array both are similar in a language .

the diffrence is that pointer is a variable and array is a newmonic .

both declration is correct
0 0 votes

In C, arrays and pointers are identical in the way they access the memory.

Hence, Option A


The major difference, however, is that the pointer identifier can take different values if we assign them to it. But the name of the array points to the base address of the array, and it can't be changed.

In plain English, a pointer A is a variable, while the array name A would be a const int*.

Answer:
Position:
Show:

Related questions

6 6 votes
1 1 answer
3.3k
3.3k views
Arjun asked Oct 18, 2016
3,287 views
Consider the following incomplete C function for reversing a singly linked list.node* reverse(node* trav){ if(trav->next) __________________ else { head - next = null; he...
5 5 votes
2 answers 2 answers
2.3k
2.3k views
Arjun asked Oct 18, 2016
2,261 views
What will be the output of the following code?#include <stdio.h #include <string.h int main() { struct mystruct{ char *name; unsigned int age; }; struct mystruct st1 = {"...
9 9 votes
2 answers 2 answers
2.4k
2.4k views
Arjun asked Oct 18, 2016
2,398 views
int foo(int n) { if(n 10000) return 1; int sum = 0, i; for( i = 0; i < n; i++) { sum += i; } return sum; }The value returned by the above function is$\Theta\left(n^2\rig...
1 1 vote
4 4 answers
5.3k
5.3k views
Arjun asked Oct 18, 2016
5,333 views
Which of the following statements is true regarding C language?S1: C is a functional languageS2: C is a declarative languageS3: C is a procedural languageS4: C is a struc...