C Programming basics

This is a discussion on C Programming basics within the C Programming forums, part of the General Programming Boards category; Guys, what's the main difference between a char and a string in C / C++?...

  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
    21,589
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 10: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, 06:25 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21