Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

What is string and what is string literal

c++ managed c++ string

  • Please log in to reply
4 replies to this topic

#1 rohit80042

rohit80042

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:Java, C++
  • Learning:C, Java, C++

Posted 04 November 2012 - 09:46 AM

1. What is diiference between char, string and varchar

Ofcourse I know char is character that can contain technically letter,digit,special symbols(i.e everything we can technically write comes here). I get to know from various sites that char is a single symbol having 1 byte and represented as for ex : 'a'

But the thing confuse me always is then why the ** we write this in some programming languages as char(10). I get to knew that it can take 10 bytes and it is a character. So it means char can be more than of one symbol ? If yes then what the ** is string? I think stirng is sequence of characters which can have from zero to finite character. Please explain me more about this if possible

What is null string? why we use 0 here. Is it means nothing or a mathematical zero?

What is literal? And what is string literal.

How these all data types represented i.e when is best to use best and what are memory occupations by these.

One more important that driver me crazy is that when to use doubles quotes and when to use single quotes in above types and also in sql database. I am using sap bo and here we use double quotes for writing if condition. I am nt sure why it is so

Please can anybody provide me link for database types also to understand them also or answer here. I will be having the best thank of my life to that guy/gal

Thanks
Rohit
  • 0

#2 sauer2

sauer2

    CC Lurker

  • New Member
  • Pip
  • 7 posts

Posted 04 November 2012 - 11:14 AM

Hi Rohit,

a literal is how raw data itself (strings and values, for instance) is represented in source code.
Some examples:

1. a string literal
"This is a string literal, the quotes are part of it"

2. a numerical literal
42.005

3. a boolean literal
true

Another, more specific example:

Let's assume, you declare a string in C and assign a value to it.
(It helps to know that there actually are no string types in C but arrays of char types instead.)

char myString[] = "Hello world";

That means:

char -> the type

myString -> the name

[] -> Array operator, used to declare the variable as an array of the type

= -> Operator

"Hello World" -> the string literal

; -> the token that seperates one statement from the next


The other questions are better answered by someone who is more genre-sawy with C and C++.
  • 0

#3 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 04 November 2012 - 05:59 PM

This smells like homework...how are you intending to apply these concepts? We have a policy of not doing people's homework for them, only helping.
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'


#4 rohit80042

rohit80042

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts
  • Programming Language:Java, C++
  • Learning:C, Java, C++

Posted 04 November 2012 - 08:09 PM

Thanks sauer2 for your kind help. I got somewhat clear picture but definetely looking to have all answers from others .

Dargueta: Sir, FYI I have completed my course in study and now a fresher in work :) I just need to have clear picture of above topics as I lear everything when only I have base the most strong....So till when I dont understand above and othef fundamental things i can't make my brain learn othr things no matter how easy they seems !!!!!!!
  • 0

#5 BlackRabbit

BlackRabbit

    CodeCall Legend

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3871 posts
  • Location:Argentina
  • Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
  • Learning:Java, Others

Posted 05 November 2012 - 12:22 AM

1. What is diiference between char, string and varchar


As sauer said, the literal is how you write it in your code, and the data type is the way that literal is represented in the computer's memory, as in how many bytes it takes and how those bytes are encoded

about varchar, that is a database data type, which means variable length string ;)

.
  • 0





Also tagged with one or more of these keywords: c++, managed c++, string

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download