C PROGRAMMING LECTURE C-language Computer Fundamentals.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Designing a Program & the Java Programming Language
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 1 – Introduction to Computers and C++ Programming Outline 1.6 Machine Languages, Assembly Languages,
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Introduction to Computing Lecture 01: Introduction to C Introduction to Computing Lecture 01: Introduction to C Assist.Prof.Dr. Nükhet ÖZBEK Ege University.
CSE1301 Computer Programming Lecture 4: C Primitives I.
Three types of computer languages
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?
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Bil104E Introduction to Scientific and Engineering Programming
 2003 Prentice Hall, Inc. All rights reserved Computer Organization Six logical units of computer 1.Input unit “Receiving” section Obtains information.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
How Create a C++ Program. #include using namespace std; void main() { cout
 2000 Prentice Hall, Inc. All rights reserved. 1 Introduction to Computers and C Programming Outline Introduction What Is a Computer? Computer Organization.
C PROGRAMMING LECTURE 17 th August IIT Kanpur C Course, Programming club, Fall by Deepak Majeti M-Tech CSE
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
COMPUTER SCIENCE I C++ INTRODUCTION
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Programming Design Ku-Yaw Chang Assistant Professor, Department of Computer Science and Information Engineering Da-Yeh University.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
Spring 2005, Gülcihan Özdemir Dağ BIL104E: Introduction to Scientific and Engineering Computing, Spring Outline 1.1Introduction 1.2What Is a Computer?
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Computer Programming I. Today’s Lecture  Components of a computer  Program  Programming language  Binary representation.
Numeric Types, Expressions, and Output ROBERT REAVES.
C++ Programming Language Lecture 1 Introduction By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Computer Organization Six logical units in every.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
History of C 1950 – FORTRAN (Formula Translator) 1959 – COBOL (Common Business Oriented Language) 1971 – Pascal Between Ada.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Introduction to Computers Outline 1.1Introduction.
Computer Science 101 Introduction to Programming.
 2008 Pearson Education, Inc. All rights reserved. 1 CISC 1600 – Computer Science I Fall 2010 Introduction to C++ Programming Chapters 1 and 2 (Deitel.
Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI CSCI.
Beginning C++ Through Game Programming, Second Edition
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
1 Programming Fundamentals How to Program in C++ How to Program in C++
Introduction to Programming
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
CPS120: Introduction to Computer Science Variables and Constants.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
Introduction to C Programming
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Introduction to Computers and Programming.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Software Engineering Algorithms, Compilers, & Lifecycle.
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.
C++ Lesson 1.
Chapter 1: Introduction to computers and C++ Programming
Getting Started with C.
C Short Overview Lembit Jürimägi.
1.6 Machine Languages, Assembly Languages, and High-level Languages
Introduction to C Programming Language
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Chapter 1: Computer Systems
Govt. Polytechnic,Dhangar
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
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.
C programming Language
Introduction to Computer Programming
C Language B. DHIVYA 17PCA140 II MCA.
Getting Started With Coding
Presentation transcript:

C PROGRAMMING LECTURE C-language Computer Fundamentals

History of C  C  Evolved by Ritchie from two previous programming languages, BCPL and B  Used to develop UNIX  Used to write modern operating systems  Hardware independent (portable)  By late 1970's C had evolved to "traditional C"

History of C  Standardization  Many slight variations of C existed, and were incompatible  Committee formed to create a "unambiguous, machine-independent" definition  Standard created in 1989, updated in 1999

Language Types  Three types of programming languages 1. Machine languages Strings of numbers giving machine specific instructions Example: Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) Example: MOV AL, NUM1 ADD AL, NUM2 MOV VAL, AL

Language Types, Cont. 3. High-level languages Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay

High-level Languages  “high-level” is a relative term  C is a relatively low-level high-level language  Pascal, Fortran, COBOL are typical high-level languages  Java, Python, Perl, VB are examples of high-level high-level languages  Application specific languages (Matlab, Javascript, VBScript) are even higher-level.

C Language C-language  C is a high-level language.  Writing a C code. {turbo C, DevC++}  For DevC++  Compiling a C code. {F9}  Compile & Execute. {F11}

Character Set of C-Langauge  Alphabetic Letters  A-Z  A-z  Numbers  0-9  Special Characters  +,-,*,/,%  {,},[,],”,, =,(,) etc C-language

Word  Reserved Words  Also called keyword  Reserved for language and language has special meanings for these reserved word  autoifbreak int case long  Registercontinue returndefault short do  sizeofdouble static else structswitch  extern typedef float union dsignedfor  unsigned goto whileenum void const  Volatile char C-language

Words C-language  User Defined Words User / Programmer defines(creates, declares) to solve his own problem Could variable, function, structure, class name  int radius; radius is a reserved word  char name[50]; Name is a reserved word

Variable Naming Rules  Can’t be reserved word  Must start with alphabetic letter or underscore only  Must not contain any special character even space character is not allowed  Not two variables can have same name within same scope  C/C++ is case sensitive  etc C-language

Codding Rules  Every statement must end with semicolon  Every program must have a main() function  We place two statements on the same line; but they must be separated with semicolon  Program must include respective header file if some required to be used in the program  Variable naming rules  etc C-language

Error  Syntax Errors  Due to violation of grammatical rules on language  int first number;// invalid  Logical Errors  Due wrong use of logic or formula  Area=3.14+radius+radius;// * must be there instead of +  Run Time Errors  Occur when specific condition meets  Divide by zero C-language

My first C program! C-language #include using namespace std; // program prints hello world main() { cout<<"Hello world!"; } Output: Hello world!

Example 1 C-language #include using namespace std; // program prints a number of type int main() { int number = 4; cout<<“Number is”<< number; } Output: Number is 4

Example 2 C-language #include // program reads and prints the same thing int main() { int number ; cout<<“enter number: ”; cin>>number; cout<<“\nNumber is ”<< number; return 0; } Output : Enter a number: 4 Number is 4

more and more C-language #include using namespace std; int main() { /* this program adds two numbers */ int a = 4; //first number int b = 5; //second number int answer = 0; //result answer = a + b; }

Operators C-language OperatorsSymbols Increment Operators++ -- (Postfix), (Prefix) Asthmatic Operators* / % + - Shift Operator > Relational Operators Bitwise Binary Operators & | ~ ^ Logical Operators&& || !

Some more Arithmetic Operators C-language  Prefix Increment : ++a  example: int a=5; b=++a; // value of b=6; a=6;  Postfix Increment: a++  example int a=5; b=a++; //value of b=5; a=6;

Some more Data Types C-language

Contd… C-language  Modulus (remainder): %  example: 12%5 = 2;  Assignment by addition: +=  example: int a=4; a+=1; //(means a=a+1) value of a becomes 5 Can use -, /, *, % also

Contd… C-language  Comparision Operators:, =, !=, ==, !, &&, ||.  example: int a=4, b=5; a<b returns a true(non zero number) value.  Bitwise Operators: >, ~, &, |,^.  example int a=8; a= a>>1; // value of a becomes 4

Operator Precedence C-language  Meaning of a + b * c ?  is a+(b*c) basically All operators have precedence over each other  *, / have more precedence over +, -.  If both *, / are used, associativity comes into picture. (more on this later)  example : 5+4*3 = 5+12= 17.