Thread: C Programming basics

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    1

    C Programming basics

    Guys,

    what's the main difference between a char and a string in C / C++?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by raghu_c
    what's the main difference between a char and a string in C / C++?
    The main difference is that a char is a char and a string is a (null terminated) string of chars.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    15
    There are a LOT of implementations of strings in c++. The best way to think of a character is a single point in memory that has a character in it, like 'A'.
    When strings are implemented in c (or sometimes c++) you have multiple points in memory where each point contains a character.

    Imagine a 1-d matrix/array of characters
    char *str1 = "abcde\0" = [a][b][c][d][e][\0]
    char str2[5] = [a][b][c][d][e][\0]
    char ch = 'a' = [a]
    ^
    *Pseudocode*

    C++ generally has managed strings that will allocate memory, free memory and give you more control over the string but the underlying concept is the same.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Learned the basics, SO ?
    By TuxPayne in forum C Programming
    Replies: 4
    Last Post: 09-11-2005, 12:32 PM
  2. Win Api Basics...
    By Devil Panther in forum Windows Programming
    Replies: 19
    Last Post: 09-09-2004, 11:28 AM
  3. C++ Basics part two
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-22-2003, 11:34 AM
  4. The Basics
    By Granger9 in forum Windows Programming
    Replies: 5
    Last Post: 09-13-2002, 05:12 PM
  5. OO Basics
    By DISGUISED in forum C++ Programming
    Replies: 3
    Last Post: 01-04-2002, 07:25 PM