C Short Overview Lembit Jürimägi.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Programming Languages and Paradigms The C Programming Language.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Primitive Variable types Basic types –char (single character or ASCII integer value) –int (integer) –short (not longer than int) –long (longer than int)
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
0 Chap. 2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations Imperative Programming, B. Hirsbrunner,
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Department of Electrical and Computer Engineering Introduction to C++: Primitive Data Types, Libraries and Operations By Hector M Lugo-Cordero August 27,
Introduction As programmers, we don’t want to have to implement functions for every possible task we encounter. The Standard C library contains functions.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Fundamental Data Types, Operators and Expressions Kernighan/Ritchie: Kelley/Pohl: Chapter 2 Chapter 2, 3.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
C++ Lesson 1.
‘C’ Programming Structures and Commands
The Machine Model Memory
Data types Data types Basic types
A bit of C programming Lecture 3 Uli Raich.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Chap. 2. Types, Operators, and Expressions
LESSON 3 IO, Variables and Operators
Programming Languages and Paradigms
Fundamental of Programming (C)
C Fundamentals & Pointers
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Programming Paradigms
Computing with C# and the .NET Framework
C Basics.
Introduction to C Programming Language
By: Syed Shahrukh Haider
Introduction to C Programming
11/10/2018.
Lexical Elements, Operators, and the C Cystem
CMSC 104, Section 4 Richard Chang
Starting JavaProgramming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
Lexical Elements, Operators, and the C Cystem
פרטים נוספים בסילבוס של הקורס
Introduction to C Programming
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Variables in C Declaring , Naming, and Using Variables.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Module 2 Variables, Data Types and Arithmetic
Programming Languages and Paradigms
Variables in C Topics Naming Variables Declaring Variables
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
INTRODUCTION TO C.
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

C Short Overview Lembit Jürimägi

Compilation Code written in C doesn’t run directly but needs to be compiled Code itself may be cross-platform but a compiled executable is not Compilers supplied by hardware vendors, operating systems, etc Compiler may be separate or integrated to IDE Compiler workflow: Code preprocessed for macro replacement, conditional compilation, source inclusion (preprocessor) Preprocessed code compiled to object code (compiler) Object code assembled to machine language (assembler) Machine language packaged into an executable (linker)

C Standards Classic ANSI C (C89/C90) C99 C11

C Syntax Case-sensitive Limited list of reserved words Sparse notation using single characters Nonessential functionality delegated to libraries Short code but hard to read

Reserved words (C89) Datatypes Type related Statements Other char, double, enum, float, int, long, short, signed, struct, union, unsigned, void Type related auto, const, extern, register, static, typedef, volatile Statements break, case, continue, default, do, else, for, goto, if, return, switch, while Other main, sizeof

Variables Typed but support implicit type conversion Defined as type followed by identifier Identifiers consist of latin letters, numbers and underscore Identifier must start with a lower-case or upper-case letter Variable can be defined anywhere in code By default the scope of the variable is limited to current block If defined outside any block then it’s a global variable (try to avoid) If identifier followed by [ ], then it’s an array

Built-in data types Type name Size Value range char, unsigned char 8 bits -128 .. 127, 0 .. 255, ASCII characters short, unsigned short, short int, unsigned short int, (int) 16 bits -32,768 .. 32,767, 0 .. 65,535 long int, unsigned long int, (int) 32 bits -2,147,483,648 .. 2,147,483,647, 0 .. 4,294,967,295 long long int, unsigned long long int, (long int) 64 bits -9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807 0 .. 18,446,744,073,709,551,615 float 1.1 × 10−38 .. 3.4 × 1038 double 2.2 x 10−308 .. 1.7 x 10308 long double 80 bits 3.4 x 10-4932 .. 1.1 x 104932 void ?

Constants Integer constants Floating point constants Characters 12, 0x1F, 055 (decimal, hecadecimal, octal) Stored as signed int unless specified otherwise (12l, 5u, 40ul) Floating point constants 3.2, 14e3 Stored as double unless specified otherwise (1.4f, 2.7l) Characters 'a' Stored as char Strings "a" Stored as character array

Examples int a; // define 32 bit signed integer, value undetermined long long unsigned int k = 0xFFFFFFFFFFFFFFFFul; // define 64 bit unsigned integer and set to max value float f = 3.4; // define 32 bit float, assign value 3.4 f = 9 / 5; // f gets value 1, since both operands are integers! double x, y, z; // define 3 variables at once int M[2] = {1, 5}; // define int array, set M[0] to 1, M[1] to 5 char S[] = "Hello"; // define character array big enough to hold string constant "Hello" S[0] = 'J'; // replace first character with 'J'

Operators Arithmetic Bitwise Assignment Boolean Comparison +, -, *, /, %, ++, -- Bitwise ~, &, |, ^, <<, >> Assignment =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>= Boolean !, &&, || Comparison <, <=, >, >=, ==, != Reference and dereference &, *, [ ] Conditional ? :

Operator precedence Operator Type () Parentheses ! Logical NOT ++ -- Increment, decrement * / % Multiply, divide, remainder + - Add, subtract << >> Shift (multiply by 2, divide by 2) < > <= >= Less, greater, less-equal, greater-equal == != Equal, not equal & Bitwise AND ^ Bitwise XOR | Bitwise OR && Logical AND || Logical OR ?: Conditional =, .. Assignment

Statements Conditional statements Loops if, else, switch, case, default Loops while, do, for, goto, break, continue

If if (expression) statement; if(a < b) x = a; if (expression) statement; else statement; if(b < c) x = c; else

Switch switch(a){ case value: statement; break; default: statement; } case 1: x = -1; break; case 2: y = 0; default: x = 1; }

While while(expression) statement; do statement; while(expression); while(i < 10) i++; a = 5; while(a > 0){ printf("%d\n", a); a--; } a = -1; do{ } while(a > 0);

For for(initialization; expression; statement) statement; for(i = 0; i < 10; i++) printf("%d\n", i); i = 20; for(; i; printf("%d\n", i--));

Functions Function definition is similar to global identifier definition but identifier must be followed by parentheses Parameters are passed by position, one way At most single return value To bypass these limitations pointers are used A program must have main function The return statement is used to return value and / or break program flow

Example int sum(int a, int b){ int x = a + b; return x; } void switchIfSmaller(int *a, int *b){ if(*a >= *b) return; int x = *a; *a = *b; *b = x;

Libraries stdio.h for input output functionality printf, scanf, fgets, fopen, feof, fclose FILE datatype stdlib.h for conversion and memory management atoi, atof, malloc, realloc, free, qsort, rand NULL constant string.h for string operations strcmp, strcpy, strlen, memcpy, memset math.h for math cos, sin, tan, acos, asin, atan, exp, log, pow, sqrt, ceil, floor, fabs time.h for date and time functions time struct tm datatype