GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 393 of 453    Print  
How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?

  
Total Answers and Comments: 5 Last Update: February 05, 2008     Asked by: dattu.kv 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 17, 2007 07:13:36   #1  
kalis Member Since: November 2007   Contribution: 3    

RE: How can a character and a string with only one c...
A character means a single alphabet. But string means a group of characters enclosed within within double quotes having a null character at the end. In case if you are in a need to use a character you can use a single character rather than a string. What is the purpose of using a single character in a string?
 
Is this answer useful? Yes | No
December 27, 2007 10:14:32   #2  
kaushalgoa Member Since: December 2007   Contribution: 7    

RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
The following program will crash -


void main()
{
char a 'a';
char *b "b";

printf(" sn" a);
printf(" sn" b);

return;
}

 
Is this answer useful? Yes | No
January 11, 2008 05:36:59   #3  
get2devi Member Since: January 2008   Contribution: 1    

RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
use c for printing a character and s for printing the string. else it'll crash
 
Is this answer useful? Yes | No
January 21, 2008 07:00:46   #4  
AkterSuriya Member Since: November 2006   Contribution: 3    

RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
There are various things to be observed for this
1. First of all while at the time of storing

single character is stored as char abc 's';
where as string having single character can be stored as char pqr[] "s";

2. single character takes one byte for storage
String (even single character is stored) takes two bytes one for one character and second for null character.

This can be verified by following C statement:

printf(" d d" sizeof(abc) sizeof(pqr));
which gives output as 1 and 2 respectively. (assuming turbo C compiler and 1 byte for char)

 
Is this answer useful? Yes | No
February 05, 2008 16:23:30   #5  
yrenster Member Since: February 2008   Contribution: 2    

RE: How can a character and a string with only one character can be differentiated? What is the internal difference between a character and string, with only one character in it?
A character is a interger in the range -127 to 127. You can set a char value using interger. for example the character 'a': char cc 141; The string "a" is not a integer a string defines a GROUP of characters and for a single character string it happens to be a group with only one member. But the nature is still a group not a member.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape