i am a to c programing..and a doubt about pointers

Reply

Join Date: Nov 2005
Posts: 5
Reputation: arun_kumar_c is an unknown quantity at this point 
Solved Threads: 0
arun_kumar_c arun_kumar_c is offline Offline
Newbie Poster

i am a to c programing..and a doubt about pointers

 
0
  #1
Nov 11th, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,335
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 236
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: i am a to c programing..and a doubt about pointers

 
0
  #2
Nov 11th, 2005
Originally Posted by arun_kumar_c
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.

Originally Posted by arun_kumar_c
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 5
Reputation: arun_kumar_c is an unknown quantity at this point 
Solved Threads: 0
arun_kumar_c arun_kumar_c is offline Offline
Newbie Poster

Re: i am a to c programing..and a doubt about pointers

 
0
  #3
Nov 13th, 2005
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: i am a to c programing..and a doubt about pointers

 
0
  #4
Nov 13th, 2005
you should not use gets, instead use fgets
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: i am a to c programing..and a doubt about pointers

 
0
  #5
Nov 13th, 2005
I should have given you the reason for that also...you can see that here
http://www.gidnetwork.com/b-56.html
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC