the c language BY SA 1972 by Ken Thompson and Dennis Ritchie.

Slides:



Advertisements
Similar presentations
the javascript language BY SA.
Advertisements

SEE C GO Provisional Title. Syntax Types int, float, double, char, void Identifiers foo Operators + - * / ^ Delimiters ; {} () “” ‘’ Keywords return,
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
the java language BY SA introduced in 1995 by Sun Microsystems.
1 Chapter Thirteen Pointers. 2 Pointers A pointer is a sign used to point out the direction.
Programming Languages and Paradigms The C Programming Language.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Pointers.
Pointers in C Rohit Khokher
Introduction To C Programming ปรีดา เลิศพงศ์วิภูษณะ ภาควิชาวิศวกรรมคอมพิวเตอร์ คณะวิศวกรรมศาสตร์ มหาวิทยาลัยเกษตรศาสตร์
CS 4800 By Brandon Andrews.  Specifications  Goals  Applications  Design Steps  Testing.
Arrays in CCS-2301, B-Term Arrays in C (including a brief introduction to pointers) CS-2301, System Programming for Non-Majors (Slides include materials.
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
CS100A, Fall 1997, Lectures 221 CS100A, Fall 1997 Lecture 22, Tuesday 18 November Introduction To C Goal: Acquire a reading knowledge of basic C. Concepts:
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
Pointers CSE 2451 Rong Shi.
Computer Science 210 Computer Organization Introduction to C.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 14P. 1Winter Quarter Pointers Lecture 14.
1 Pointers and Strings Chapter 5 2 What You Will Learn...  How to use pointers Passing arguments to functions with pointers See relationship of pointers.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Introduction to Programming
Arrays in CCIS 1057 Fall Arrays in C (with a brief Introduction to Pointers) CIS 1057 Computer Programming in C Fall 2013 (Slides include materials.
CS 100Lecture 211 Announcements P5 due on Thursday FINAL EXAM Tuesday August 10, 8AM, Olin 155 Review sessions on Thursday and Friday Final grades posted.
Data Type. Syntax Rules Recap keywords breakdoubleifsizeofvoid caseelseintstatic..... Identifiers not#me123th scanfprintf _idso_am_igedd007 Constant ‘a’‘+’
Elementary C++. Procedural Programming Split your problem into simpler parts then solve each part separately Recognize common parts and solve them only.
Lecture 12: Pointers B Burlingame 25 Nov Announcements Homework 6 due Homework 7 posted, due with the final  Final prep Take home Lab posted tonight.
Functions & Pointers in C Jordan Erenrich
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Pointers *, &, array similarities, functions, sizeof.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Pointers A pointer type variable holds the address of a data object or a function. A pointer can refer to an object of any one data type; it cannot refer.
FUNCTIONS (CONT). Midterm questions (21-30) 21. The underscore can be used anywhere in an identifier. 22. The keyword void is a data type in C. 23. Floating.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
C Programming Lecture 3 : C Introduction 1 Lecture notes : courtesy of Woo Kyun and Chang Byung-Mo.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
Chapter 7 Pointers Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
BASIC C PROGRAMMING LANGUAGE TUTORIAL infobizzs.com.
Windows Programming Lecture 03. Pointers and Arrays.
1 Memory, Arrays & Pointers. Memory 2 int main() { char c; int i,j; double x; cijx.
From Algorithms to Programs Both are sets of instructions on how to do a task Algorithm: –talking to humans, easy to understand –in plain (English) language.
Lecture 11: Pointers B Burlingame 13 Apr Announcements Rest of semester  Homework Remaining homework can be done in pairs, turn in one paper with.
C language--Introduction. History 1970: B by Ken Thompson at AT&T Bell Lab 1972: C by Dennis Ritchie and Ken Tompson at At&T Bell Lab for UNIX 1978: “The.
Computer Organization and Design Pointers, Arrays and Strings in C
The Machine Model Memory
Computer Science 210 Computer Organization
Revision Lecture
C Basics.
Introduction to C Programming Language
By: Syed Shahrukh Haider
Data Type.
Methods and Parameters
Computer Science 210 Computer Organization
Conversions of the type of the value of an expression
Data Type.
Govt. Polytechnic,Dhangar
Introduction to C Topics Compilation Using the gcc Compiler
CS100A Lecture November 1998 Prelim 3 Statistics Maximum 94
C++ Pointers and Strings
Introduction to C Topics Compilation Using the gcc Compiler
The C Language: Intro.
The Stack.
Names of variables, functions, classes
Data Type.
C Language B. DHIVYA 17PCA140 II MCA.
Pointer Arithmetic By Anand George.
C++ Pointers and Strings
Introduction to C CS 3410.
Presentation transcript:

the c language

BY SA

1972 by Ken Thompson and Dennis Ritchie

developed concurrently with Unix C++ and Objective-C in 1980’s ANSI C89, C90, and C99 GCC (Gnu Compiler Collection) MSVC (Microsoft Visual C++)

imperative/procedural statically typed weakly typed

control of memory explicitly manipulate individual bytes “portable assembly” compact data manual allocation

calling convention assembly from C C from assembly (how functions are called in machine code)

systems programming (operating systems, device drivers) performance-sensitive code (games, media players)

basic data types char 1-byte signed integer int n-byte signed integer float single-precision floating- point double double-precision floating-point

declarations type name; int monkey; float zebra;

functions returnType name(parameters) {body}

int square(int n) { return n * n; } int cube(int n) { return square(n) * n; }

char foo(int a, float b, float c) { … }

casting (type) expression int x = 35; foo((char) x);

!0// 1 !1// 0 !0.6// 0 !3// 0 !-76.5// 0

void roger(int x) { if (x == 3) { int z = 9; foo(z); } else { bar(z); // z does not exist } ack(z); // z does not exist }

int main() { printf(“Hello, world!”); return 0; }

value variables float a = 9.3;

pointers (a data type representing an address) int *foo; double *bar; char *ack;

reference operator &lvalue int i; int *p; p = &i; char c; int *p; p = &c; // error

reference operator &lvalue int i; int *p; p = &i;

dereference operator *pointer int i = 3; int *p; p = &i; i = *p + 2;

int i; int *p; p = &i; *p = 6;

pointer arithmetic int i; int *p; p = &i + 2; i = *p;

can subtract a pointer from a pointer can’t add a pointer to a pointer

char *p; p = (char *) 0xB000FFFF; char c = *p;

int *p; p = 0; if (p) { … } // false

pointer comparisons == != > < >= <= !

weak typing (can violate data types) float f; f = 98.6; f = f – 2; char *p; p = (char *)&f + 2; *p = 1;

memory allocation malloc free

void *p; p = malloc(5); float *f; f = malloc(13); … free(p); free(f);

sizeof operator sizeof type sizeof int sizeof double sizeof(float *)

int *p; p = malloc(7 * sizeof(int)); *(p + 6) = 35; … free(p);

int *p; p = malloc(7 * (sizeof int)); if (p == 0) { … // allocation failed } else { … // allocation succeeded free(p); }

array (a stack-allocated contiguous block of memory) type name[size]; float jack[8]; char jill[200];

int i[32]; char c[11]; int *p; p = i; *i = -6; *(i + 1) = 8; *(c + 7) = (char) 5;

int sum(int *arr, int n) { int i = 0; int sum = 0; while (i < n) { sum = *(arr + i) + sum; i = i + 1; } return sum; }

int a[30]; … int sumA = sum(a, 30); int *b = malloc(20 * sizeof(int)); … int sumB = sum(b, 20);

char *fred() { char c[30]; return c; }

char *fred() { char *c = malloc(30 * sizeof(char)); return c; } char *foo = fred(); … free(foo);

strings char *s = “abc”; char b = *(s + 1); int i = strlen(s);

structure (a programmer-defined compound data type) struct typeName {members}; struct typeName name; instance.member

struct cat { char *name; int age; }; // semi-colon! struct cat mittens; mittens.name = “Mittens”; mittens.age = 5;

struct cat mittens; struct cat fluffy; … mittens = fluffy; struct cat *p = &fluffy; mittens == fluffy // illegal

struct cat cats[8]; (*cats).name = “Oscar”; (*(cats + 1)).name = “Kitty”;

struct cat *cats = malloc(8 * (sizeof struct cat));