hi guys ,
I am a first year student!
can anyone help ..
the code. is .
main()
{
char *b="abc";
printf("%s",b);
}
the output is :abc.
my doubt is :
how can we assign a string constant to a pointer.And when we assign like this is a character array with the name b[] is initialised to "abc"?
and can anyone expalin this program:
#include<stdio.h>
main()
{
char *j="abc";
printf("%u\n%u\n","abc",&"abc");
printf("%u\n%u",j[1],j[0]);
}
and the out put was :
415
419
98
97
please help... :confused:

my doubt is :
how can we assign a string constant to a pointer.And when we assign like this is a character array with the name b[] is initialised to "abc"?

The pointer is assigned the address of an unnamed array which contains the string literal.

and can anyone expalin this program:
the out put was :
415
419
98
97

Well, first of all the behavior is undefined so what you see does not necessarily mean anything. At best you might be seeing the address of a string literal presented as an integer for the first two. The second two merely show that your system uses ASCII for characters.

thank you for your reply...hey i have another doubt too..i declared a character pointer....
when i assign a value i.e .. a string to a character pointer using gets()...i get the warning possible use of that 'character pointer'before declaration..but the program works :rolleyes: ...do you know why?

you should not use gets, instead use fgets

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.