What To Do To Learn C & C++

About programming and getting involved with Linux Mint development
Post Reply
billmartinn
Level 1
Level 1
Posts: 1
Joined: Tue Sep 14, 2021 9:37 am

What To Do To Learn C & C++

Post by billmartinn »

Dear All,

I have just joined this forum to get an answer of my question. Please do not mark me a spammer as I am not.

I want to learn C & C++ but I do not know where to start. Could you please share your personal experience and guidance so I can start learning it. I have never written any code in my enter life.

Please lead me :)
User avatar
JoeFootball
Level 12
Level 12
Posts: 4136
Joined: Tue Nov 24, 2009 1:52 pm
Location: /home/usa/mn/minneapolis/joe

Re: What To Do To Learn C & C++

Post by JoeFootball »

billmartinn wrote: I want to learn C & C++ but I do not know where to start.
C Tutorial for Beginners
https://www.youtube.com/watch?v=KJgsSFOSQv0

C++ Tutorial for Beginners
https://www.youtube.com/watch?v=vLnPwxZdW4Y

Edit: Adding Python, if interested ...

Python Tutorial for Beginners
https://www.youtube.com/watch?v=rfscVS0vtbw
Last edited by JoeFootball on Wed Sep 15, 2021 7:37 am, edited 1 time in total.
User avatar
Moem
Level 21
Level 21
Posts: 13555
Joined: Tue Nov 17, 2015 9:14 am
Location: The Netherlands
Contact:

Re: What To Do To Learn C & C++

Post by Moem »

billmartinn wrote:
Tue Sep 14, 2021 9:42 am
I have just joined this forum to get an answer of my question.
Then you may not have made the best choice there. Most of us here are not programmers. Aren't there any forums for programmers and people who want to become one?
Image

If your issue is solved, kindly indicate that by editing the first post in the topic, and adding [SOLVED] to the title. Thanks!
deepakdeshp
Level 19
Level 19
Posts: 9883
Joined: Sun Aug 09, 2015 10:00 am

Re: What To Do To Learn C & C++

Post by deepakdeshp »

You can try and post on stackoverflow. This forum is Linux Mint help.
If I have helped you solve a problem, please add [SOLVED] to your first post title, it helps other users looking for help, and keeps the forum clean.
Regards,
Deepak

Mint 20.1 Cinnamon 64 bit with AMD A8/7410 / 8GB
Mint 20.1 Cinnamon AMD Ryzen3500U/8gb
rene
Level 18
Level 18
Posts: 8401
Joined: Sun Mar 27, 2016 6:58 pm

Re: What To Do To Learn C & C++

Post by rene »

Step 1 would generally be to not conflate C and C++. If you learn C++ then learning basic C is to some degree automatic but conversely this is very much not the case: C++ is a very different language than C; when used as intended, object oriented, C++ inherits basic syntax from C but that's also just about the only thing it still does: C++ uses a significantly different programming paradigm and is a much larger language so as to support and make full use of such.

That is, what I'm saying is that you should explicitly know that you want to learn C++ if starting to learn C++; not just do so by wanting to know "C & C++" as a matter of you believing the two to be close anyway; C++ is not close to C in any real, functional sense.

Wanting to learn C can make sense even as a first language: in in fact much the same way as it gives a boost when later learning C++ even if as to those mentioned basics only/mostly, it provides for a similar boost for in fact many languages; is one of the lower level languages still in common use and is as such methodologically often more or less a template for other languages -- and certainly on UNIX/Linux where C can be termed "the native programming language".

That however also says that you very much need to DIY in C; that if you do it right, e.g. manual, boring error handling tends to be more than half your code and that even something basic like string parsing tends to for a large part be roll-your-own. For an actual, real first language this is not generally good: it disallows focusing on programming constructs as such; forces to concentrate on what in a language such as Python is or can be insignificant details, and tends to moreover say that you'd not these days use it just to "get something done". There's few for whom C was actually a first language, even if only if an earlier one was only e.g. childhood BASIC. If you're the type and frankly the age, sure, but as a first language for someone past 30... maybe consider e.g. Python.

If you insist; C aficionados will/would to this day point you to K&R;

https://www.amazon.com/Programming-Lang ... 131103628/

You will want to ignore that advise, but I do suggest you go the old-fashioned book route. There's just little more effective for learning than the linearity which a book naturally implies. I have no personal favourites but if I quickly search this seems to not be considered bad:

https://www.amazon.com/Programming-Abso ... 0789751984

But, then --- be very certain then that you in fact want to. I would generally and as a first language much more advise e.g.

https://www.amazon.com/Learning-Python- ... 1449355730

with or without https://www.amazon.com/Python-Pocket-Re ... 1449357016
User avatar
SMG
Level 18
Level 18
Posts: 8260
Joined: Sun Jul 26, 2020 6:15 pm
Location: USA

Re: What To Do To Learn C & C++

Post by SMG »

billmartinn wrote:
Tue Sep 14, 2021 9:42 am
I want to learn C & C++ but I do not know where to start.
I suggest reading this thread Wanting to learn 'C' but gcc not installing as there is a discussion of why learning python might be a better choice than learning C.
Image
A woman typing on a laptop with LM20.2 Cinnamon.
ivar
Level 4
Level 4
Posts: 218
Joined: Sun Mar 21, 2021 10:30 pm
Location: far north

Re: What To Do To Learn C & C++

Post by ivar »

billmartinn wrote:
Tue Sep 14, 2021 9:42 am
I have never written any code in my enter life.
I wrote some stuff in Basic 40 years ago but I'd rate my programming skills to be very poor. I'm starting to study Python, as suggested elsewhere in this thread , as I suspect the learning curve to be quite a bit more gentle. I'd think with some basic grasps of programming under the belt, it will be much easier to learn other programming languages
xanaki
Level 1
Level 1
Posts: 10
Joined: Fri Sep 17, 2021 8:40 am
Location: Finland
Contact:

Re: What To Do To Learn C++

Post by xanaki »

This is a bit longish so hope you have time to read :-)

When I started studying programming initially, I mean programming generally not just C/C++, I found a perfect way that fits for me and my little male tunnel brains. That was 36 years ago, I was 12 years old.

I started copying the games I was playing on my current computer at that time. Okay, the programming language was initially Basic. But.

My point is that the best way to learn new programming language for me is to pick up a project and just start implementing it. You will bump into big obstackles but you will solve them as you go forward with your project. Whenever you face some issue you do not know to do, study some, find information and you will learn.

Do you prefer to watch videos or learn by reading? I prefer the reading method. But that comes from the fact that when I was learning programming, the books were the only source of information, there was no Internet :). However, I have *never* read a programming book from cover to cover before starting to do my task. I read the basics and start implementing as soon as I am confident enough to be able to do something.

When I want to learn a new programming language, I will always pick up a project I want to do. Then start tackling it and the challenges, step by step.

I can give you one good practice I've been using myself in the past many times in different environments. I used this exact task 3 months ago when I started (FINALLY!) learning Python.

Task: Implement a console program which can show a binary file in ASCII hexadecimal representation.
The program shall take an argument telling how many bytes per row are displayed and another argument for how many lines are displayed out. The program always reads from the beginning of the file, for this excersise.
To start the application you use following syntax:
hextype.exe -i <filename> [-l <linecount>] [-b <bytes_per_row>]
Where
-i defines the input file, binary or text, whatever
-l defines how many lines are displayed. Optional. if omitted displays the whole file
-b defines how many bytes per row are displayed. Optional, if omitted displays 16 bytes per row.
Desired output format:

OFFSET (hex, 32-bit) : Bytes in ASCII (hex) : ASCII characters for the bytes, unprintable as '.'

e.g. for command "hextype.exe -i myfile.bin -l 3":

Code: Select all

00000000 : 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f : ................
00000010 : 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f :  !"#$%&'()*+,-./
00000020 : 30 31 32 41 42 43 61 62 63 64 65 66 67 68 69 6a : 012ABCabcdefghij
For reference, ASCII table can be found here., There are many alternatives.

Challenges to conquer:
  • How to get program arguments
  • How to open (and close) a file from filesystem
  • How to read the file in binary format
  • How to process the read file data
  • How to convert the bytes to ASCII representation
  • How to output the ASCII bytes to console output
  • How to format the output as required by the task
  • ...
For the binary -> ASCII conversion here's an "advanced" example I made few weeks ago. It uses templates and streams for conversion between binary<->ASCII bytes, words and longs.

This task makes you to dive into many fundamental concepts in any programming language. For example:
  • How to get program arguments
  • Control and program structures
  • Arrays and/or containers
  • Input/output, file and console
  • Error handling
  • ...
Always do incrementally, do one task and test it. Then expand. No need to tackle all the challenges at once :-) You would be overwhelmed very easily.

Here are some pointers you could start learning C++ from:

Written
Here's a written C++ tutorial which goes step by step:
C++ Tutorial @ w3schools.

Another nice tutorial from basics to advanced:
C++ Language @ cplusplus.com

Another good tutorial here:
Learn C++, simply easy learning @ tutorialspoint.com

Here's a collaborative collection of tutorials and information on C and C++:
Coding Den Wiki

FAQ in question/answer format:
Written C++ FAQ for newbies and veterans

Once you get to actually doing something you will eventually bump into this site for C++ reference up to C++20 standards:
C++ Reference

That one is quite technical, friendlier version is here @ cplusplus.com

Videos
A friend of mine has many good videos on C++ programming here from basics to advanced concepts:
One Lone Coder (javidx9)

If you type a YouTube search for example "C++ tutorial for beginners" you will find tens if not hundreds of channels which teach you C++, step by steam.

Finally, if you are interested My GitHub has some basics and some advanced stuff. And if anything else does not help use Google. Just type a question and you'll find many solutions, for example "C++ output text to console" will surely give you answers :P

Good luck! It's fun!
Feel free to ask any questions if you so want, I'll try to answer. <3
Last edited by xanaki on Sat Sep 18, 2021 12:48 pm, edited 1 time in total.
Bring me a shrubbery, Shrubbery of Mint. Ni!
From Finland with love and liquor since 1972.
jmorris84
Level 3
Level 3
Posts: 146
Joined: Mon Mar 19, 2012 6:40 pm

Re: What To Do To Learn C & C++

Post by jmorris84 »

John's tutorials at caveofprogramming.com are very helpful for learning C++.
rene
Level 18
Level 18
Posts: 8401
Joined: Sun Mar 27, 2016 6:58 pm

Re: What To Do To Learn C & C++

Post by rene »

xanaki wrote:
Sat Sep 18, 2021 5:35 am
Task: Implement a console program which can show a binary file in ASCII hexadecimal representation.
So as to emphasize my "get something done" remark; below is a short and quite to the point Python implementation of that specification. That print() statement requires a lot more code in e.g. C and error handling as to e.g. open/read can moreover simply be left to Python.

N.B. Dislike that you kept the "C/C++" language in the reply; C++ really is a very different language than C is.

Code: Select all

#!/usr/bin/env python3

import argparse
import string

parser = argparse.ArgumentParser()
parser.add_argument('-i', required=True, metavar='<filename>')
parser.add_argument('-l', type=int, default=float('inf'), metavar='<linecount>')
parser.add_argument('-b', type=int, default=16, metavar='<bytes_per_row>')
args = parser.parse_args()

p = [ ord(c) for c in string.digits + string.ascii_letters + string.punctuation + ' ' ]

f = open(args.i, 'rb')

o = 0
while args.l > 0:
    d = f.read(args.b)
    n = len(d)
    if n == 0:
        break

    print(('{:08x} : ' + n * '{:02x} '
                       + (args.b - n) * '   '
                       + ': '
                       + n * '{:c}').format(o, *d, *[c if c in p else ord('.') for c in d]))

    if n < args.b:
        break
    o += args.b
    args.l -= 1

f.close()
xanaki
Level 1
Level 1
Posts: 10
Joined: Fri Sep 17, 2021 8:40 am
Location: Finland
Contact:

Re: What To Do To Learn C & C++

Post by xanaki »

Sorry for the C :) I know the difference. I just don't edit the topics when I reply to messages.

I don't have my implementation of that Hextype I implemented when I trained Python during summer time. It was done at work as a part of induction so it's their possession now. o.O.

I'll check your implementation later but it at least looks pretty compact. I remember my implementation was longer :)

EDIT: I removed the C part from my message as as you said I only spoke about C++ in my message. <3
Bring me a shrubbery, Shrubbery of Mint. Ni!
From Finland with love and liquor since 1972.
rene
Level 18
Level 18
Posts: 8401
Joined: Sun Mar 27, 2016 6:58 pm

Re: What To Do To Learn C & C++

Post by rene »

Thanks; I always feel it a fairly important point to make. C++ by name gives the impression of being C and a bit but, yeah, no, it absolutely is not. It's C and a shitload at least, and more realistically and when used as intended, a shitload sprinkled with a bit of C-inspired syntax. People aiming to learn either should I feel explicitly elect for either.
Israel Parker
Level 1
Level 1
Posts: 3
Joined: Fri Sep 17, 2021 7:02 am

Re: What To Do To Learn C++

Post by Israel Parker »

xanaki wrote:
Sat Sep 18, 2021 5:35 am
This is a bit longish so hope you have time to read :-)
...
Thank you very much for such a detailed answer.
Last edited by SMG on Tue Oct 12, 2021 10:14 am, edited 1 time in total.
Reason: Shortened quote so response would be easier to see.
spicys
Level 1
Level 1
Posts: 3
Joined: Mon Oct 18, 2021 11:40 am

Re: What To Do To Learn C & C++

Post by spicys »

I found many tutorials on YouTube also. I combine work and study right now but with some help of cheap writing paper I got goot grades and saved my time. They are pro in writing and proofreading. Useful service for students.
Post Reply