Presentation is loading. Please wait.

Presentation is loading. Please wait.

Let’s start from the beginning

Similar presentations


Presentation on theme: "Let’s start from the beginning"— Presentation transcript:

1 Let’s start from the beginning

2 The C language Dates back to 1972 with newer versions of it still being developed Influential to most of the widely used languages today Has an objective sibling C++ According to TIOBE index, #2 used language in the world (#3 is C++) General purpose language Compiled from source code Works on almost anything Does not contain magic Basic, but fast 2018 Risto Heinsar

3 Use cases Embedded systems Hardware drivers
Operating system kernels (Linux, Windows, Mac OS, Android, iOS) Web servers (nginx, apache) Database management systems (Oracle, MySQL, PostgreSQL, MariaDB) Many modern languages use modules written in C Etc 2018

4 Being stylish – blue.pri.ee/ttu/coding-style
You should always save the file with .c extension before writing the code – this way the editor will help you write it Look into the style guide provided The style guide is important for both of us – using a good style makes you look professional and makes it easier to read and fix your code Comment your code – this way we will understand, you will remember and your friend can help Indent before, not after – why work to indent and make your code readable, let the IDE do it for you and not worry about it 2018

5 The code (hello.c) 2018

6 Some properties of the C language
Variable types must be set and declared before using them. It’s often recommended to do it in the beginning of the function. Do not use uninitialized variables Most of the lines end with a semicolon, but not all! For storing multiple characters (text), an array of characters must be created for which we need to specify a size Text must always have room for 1 extra character (terminator) For reading a single value (e.g. number), ampersand (&) symbol must precede the variable name. This is not the case for output. Comments can be made in two ways // they can be preceded by two forward slashes /* or they can be between the forward slash and asterisk symbols */ 2018

7 Our program #include <stdio.h> – this line includes the standard input and output library to your program (for functions printf(), scanf() e.t.c.) int main(void) main – this is the first part to run (and looked for) when executing your program int – when your codes finishes execution, an integer must be returned void – indicates, that nothing will be passed to the program when executing return 0 – this returns a value to whatever called the problem and in this case, ending the program. Code 0 indicates that no errors occurred during this and the program finished successfully. 2018

8 Basic data types Data Data type Format Examples Integers int %d
1, 3, -55, 0 Floating point numbers float, double %f, %g 1.2, -5.5, 1.0, 0.0, -0.0, 5.2e3, f Character char %c ‘a’, ‘x’, ‘-’, ‘ ‘ Text, string char [] %s „Hello“, „Lorem ipsum“ Truth value bool True (1), false (0) 2017 Risto Heinsar

9 Input and output <stdio.h> is the standard input-output library
This is only one of the libraries that we’ll use, many more to come printf() – used for formatted printing into the console printf("Hello! \n"); scanf() – used to get formatted user input from console scanf("%s", name); %s – format for text scanf("%d", &birthYear); %d – format for integer Don’t be afraid to experiment and look further 2018

10 Algorithms An algorithm is a step-by-step guide to solving a problem
They can be for real-word situations like customer-administrator relations, but are mostly used in mathematics and IT. Algorithms help to define processes that can be understood by multiple parties in the same way UML activity diagrams mostly consist of actions, decisions, forks and joins (for parallel activities), comments, initial and end nodes. Actions used in this program: printing, reading input and calculations. No decisions, forks or joins were used in this program. 2018

11 Hello.c algorithm 2018


Download ppt "Let’s start from the beginning"

Similar presentations


Ads by Google