14 Replies - 2547 Views - Last Post: 04 April 2017 - 01:00 PM Rate Topic: -----

#1 Alex Kostas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-April 17

C or C++?

Posted 03 April 2017 - 11:06 AM

Hello all!
I am a student and I want to learn C++. I have no experience in C (except for some Arduino projects I made) and I had read that someone can't understand C++ if he has not experience in C. I think that it is better to learn C++ than C. Can I learn C++ without learning C or I must learn C at first? Thanks for your replies.
Is This A Good Question/Topic? 0
  • +

Replies To: C or C++?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13141
  • View blog
  • Posts: 52,064
  • Joined: 12-June 08

Re: C or C++?

Posted 03 April 2017 - 11:09 AM

Never learned c by itself.. Was tossed into c++ and did fine.
Was This Post Helpful? 1
  • +
  • -

#3 Alex Kostas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-April 17

Re: C or C++?

Posted 03 April 2017 - 11:11 AM

OK thanks!
Was This Post Helpful? 0
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1259
  • View blog
  • Posts: 4,965
  • Joined: 09-June 09

Re: C or C++?

Posted 03 April 2017 - 11:15 AM

C and C++ are different languages. There is no prerequisite to learn C before C++ and vice versa.
Was This Post Helpful? 1
  • +
  • -

#5 integra94  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 26
  • Joined: 01-April 17

Re: C or C++?

Posted 03 April 2017 - 11:55 AM

CppCon 2015: Kate Gregory ôStop Teaching C": https://www.youtube....h?v=YnWhqhNdYyk

A nice perspective. Although I started with ASM through C to end up at C++. And you should start right away with the current standard, which is C++14.
Was This Post Helpful? 1
  • +
  • -

#6 Sam Hobbs  Icon User is offline

  • New D.I.C Head

Reputation: 11
  • View blog
  • Posts: 43
  • Joined: 01-April 17

Re: C or C++?

Posted 03 April 2017 - 12:41 PM

C and C++ are the same except that C is a subset of C++. Except for minor details, anything you do in C will also work in C++. So the only reason to learn C first is to know what is not available in C that is in C++.
Was This Post Helpful? 0
  • +
  • -

#7 jimblumberg  Icon User is offline

  • member icon

Reputation: 5214
  • View blog
  • Posts: 16,221
  • Joined: 25-December 09

Re: C or C++?

Posted 03 April 2017 - 01:05 PM

Quote

C and C++ are the same except that C is a subset of C++.

No, C and C++ are quite different but similar languages. They may have started with a common base, but today there are quite few a syntactic differences between the languages and the list grows with every new version of the two standards. But probably the biggest difference is the mindset you must use when programming the two languages. C is predominately a procedural language while C++ is more geared to OOP methods. IMO, if you treat C++ as C with classes, as you seem suggest, you will miss most of the true benefits of C++.


Jim

This post has been edited by jimblumberg: 03 April 2017 - 01:06 PM

Was This Post Helpful? 2
  • +
  • -

#8 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1839
  • View blog
  • Posts: 6,580
  • Joined: 19-February 09

Re: C or C++?

Posted 03 April 2017 - 01:45 PM

Yes, there is a lot of overlap with the languages and many describe C as a subset of C++.

One view is, C and C++ are the same with some differences, another view is C and C++ are different with some similarities. So a dialogue may ensue much like - 'which end of the egg should be opened'.
Was This Post Helpful? 0
  • +
  • -

#9 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5669
  • View blog
  • Posts: 19,171
  • Joined: 05-May 12

Re: C or C++?

Posted 03 April 2017 - 05:24 PM

View PostSam Hobbs, on 03 April 2017 - 03:41 PM, said:

C and C++ are the same except that C is a subset of C++. Except for minor details, anything you do in C will also work in C++. So the only reason to learn C first is to know what is not available in C that is in C++.


No. Try this perfectly valid C program that will not compile in C++.

void * GetPointerToFirstChar(char *haystack, char needle)
{
    if (!haystack)
        return haystack;

    while (*haystack && *haystack != needle)
        haystack++;
    return *haystack == needle ? haystack : 0;
}

int main()
{
    char * found = GetPointerToChar("C++", 'C');
    return 0;
}


Was This Post Helpful? 0
  • +
  • -

#10 integra94  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 26
  • Joined: 01-April 17

Re: C or C++?

Posted 03 April 2017 - 10:57 PM

Skydiver Because the linker will fail to find the function GetPointerToChar? In either language?
Was This Post Helpful? 1
  • +
  • -

#11 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5669
  • View blog
  • Posts: 19,171
  • Joined: 05-May 12

Re: C or C++?

Posted 04 April 2017 - 04:52 AM

Oops sorry for that. Typing on a phone. Let me fix the function names:

void * GetPointerToFirstChar(char *haystack, char needle)
{
    if (!haystack)
        return haystack;

    while (*haystack && *haystack != needle)
        haystack++;
    return *haystack == needle ? haystack : 0;
}

int main()
{
    char * found = GetPointerToFirstChar("C++", 'C');
    return 0;
}



The issue is type safety. C will let you assign the void * to any other pointer, but C++ will not. Type safety is not a minor detail in C++, while C is a lot looser about types and type conversions.
Was This Post Helpful? 1
  • +
  • -

#12 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 454
  • View blog
  • Posts: 1,176
  • Joined: 31-May 11

Re: C or C++?

Posted 04 April 2017 - 06:20 AM

If you will treat C as a subset of C++, or C++ as a superset of C, then you'll soon end up with some false assumptions. I'd rather treat them as similar but different (since they are so) languages that have their own best practices, better and worse ways to teach and learn them, built-in features, etc.

If you want to learn C++ - learn C++. Maybe allocate some time for yourself at a later date to see what C is all about and how it differs, if you're curious. I can't imagine it would hurt you then. ; )

If integra94 wouldn't link to "Stop Teaching C" - I probably would. It's a good video.

This post has been edited by Xupicor: 04 April 2017 - 06:23 AM

Was This Post Helpful? 4
  • +
  • -

#13 integra94  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 26
  • Joined: 01-April 17

Re: C or C++?

Posted 04 April 2017 - 10:21 AM

Skydiver I know, I was just being cheeky. 😇 And yes, that would be the difference, my C++ code is filled to the brim with reinterpret_cast (hyperbole) as I really like to work in low level memory access.
Was This Post Helpful? 0
  • +
  • -

#14 Alex Kostas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-April 17

Re: C or C++?

Posted 04 April 2017 - 10:55 AM

Thanks to all of you for your replies!!!
After considering what you have said I decided to learn C++ and later, if I have free time, I will learn C.
Was This Post Helpful? 0
  • +
  • -

#15 Sam Hobbs  Icon User is offline

  • New D.I.C Head

Reputation: 11
  • View blog
  • Posts: 43
  • Joined: 01-April 17

Re: C or C++?

Posted 04 April 2017 - 01:00 PM

I hope people will agree that the issue of whether C and C++ are similar is controversial. Many people have differing opinions. I think that the question of which to learn first implies that there is a similarity and overlap. If C++ has no more compatibility than C# and Java have with it then the question becomes which of all of them should be learned first.

I think it would help to provide links as the following except it would help to provide an article like these that is less technical and more appropriate for beginners. There might be one already but I don't know where any are.


This post has been edited by Sam Hobbs: 04 April 2017 - 01:02 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1