H.Melikian Introduction on C C is a high-level programming language that forms the basis to other programming languages such as C++, Perl and Java. It.

Slides:



Advertisements
Similar presentations
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
 2005 Pearson Education, Inc. All rights reserved Introduction.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
Chapter 1: Introduction
C Programming for engineers Teaching assistant: Ben Sandbank Home page:
Structure of a C program
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
CS1061 C Programming Lecture 2: A Few Simple Programs A. O’Riordan, 2004.
C programming.
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?
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Introduction to a Programming Environment
C programming Language and Data Structure For DIT Students.
Introduction to C Topics Compilation Using the gcc Compiler
Introduction to C. A Brief History Created by Dennis Ritchie at AT&T Labs in 1972 Originally created to design and support the Unix operating system.
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
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.
Computer Science 210 Computer Organization Introduction to C.
Introduction to C Programming. A Brief History u Created by Dennis Ritchie at AT&T Labs in 1972 u Originally created to design and support the Unix operating.
Gator Engineering 1 Chapter 2 C Fundamentals Copyright © 2008 W. W. Norton & Company. All rights reserved.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
1 Agenda Administration Background Our first C program Working environment Exercise Memory and Variables.
CS 114 – Class 02 Topics  Computer programs  Using the compiler Assignments  Read pages for Thursday.  We will go to the lab on Thursday.
The Java Programming Language
Programming With C.
C Programming Laboratory I. Introduction to C Language /* the first program for user */ #include int a=0; int main(void) { printf(“Hello World\n”); return.
CMSC 104, Version 9/011 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program 104 C Programming Standards and Indentation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
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:
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
Software Engineering Algorithms, Compilers, & Lifecycle.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 1.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Last week: We talked about: History of C Compiler for C programming
Chapter 10 Programming Fundamentals with JavaScript
Computer Science 210 Computer Organization
CSC201: Computer Programming
Chapter 2 - Introduction to C Programming
C Programming Hardik H. Maheta.
Objectives Identify the built-in data types in C++
Introduction to C Programming Language
Chapter 2 - Introduction to C Programming
Computer Science 210 Computer Organization
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Govt. Polytechnic,Dhangar
Chapter 2 - Introduction to C Programming
C programming Language
Chapter 2 - Introduction to C Programming
The C Language: Intro.
Presentation transcript:

H.Melikian Introduction on C C is a high-level programming language that forms the basis to other programming languages such as C++, Perl and Java. It was developed by a guy called Dennis Ritchie in He named it C because there was an existing programming language called B. You should also get a C compiler and write and test your own programs I learnt best from my (many) careless mistakes. There are many free compilers available on the net. For freeware, shareware and demo programs, try performing a search at: So why should you learnhttp://download.cnet.com C? Well, because it opens the doors to other languages like C++, Java.

H.Melikian Syntax The C code you write is called the SYNTAX. Syntax is a mixture of: v C keywords like int, for and return. v Constants and variable. v Operators like + (arithmetic "addition"), || (logical "or") and & (the "address of" operator). v Note that C is CASE SENSITIVE! v “White space“ in a C program does not affect. Use extra spaces to make your programs more readable

H.Melikian Compilers Microsoft's Visual C (Room 106 & 209) This is a powerful package and is suitable for people who are interested in software engineering. In general, C++ packages are fine for compiling C programs – the compiler executed depends on the extension of your source file(s). UNIX-based compiler (gcc available on laplace ). The command for compiling is of the form: % gcc world.c -o world. The filename after cc is the file to be compiled, which is "world.c" in this case, the filename after -o is the output file, which is "world". The output filename is the word you type to run the program.

H.Melikian Commenting Your Code v You can add comments to your code by enclosing your remarks within /*and */. However, nested comments aren't allowed v A few properties of comments: They can be used to inform the person viewing the code what the code does. This is helpful when you revisit the code at a later date. The compiler ignores all the comments. Hence, commenting does not affect the efficiency of the program. v You can use /* and */ to comment out sections of code when it comes to finding errors, instead of deletion

H.Melikian Examples /* Comments spanning several */ /* lines can be commented*/ /* out like this!*/ /* But this is a simpler way of doing it! */ // These are C++ /* /* NESTED COMMENTS ARE ILLEGAL!! */ *

H.Melikian Creating Executable Programs There are several tasks that need to be performed before you can run a program: coding, compiling and linking.coding 1. You have to write the source code in C. You declare which header files you want to include within the source code. The source code must be saved with the extension.c 2. Then you run the compiler, which translates the source code into machine, or binary code, which the computer can understand. Computers do NOT understand C ! 3. Sometimes the source code is still lacking some parts, so after going through the compiler, the code is passed through a LINKER. This basically "links" the source code to other library or object files so that the final binary code is produced.

H.Melikian Hello World The #include Directive v Header Files Header files have the extension.h and the full filename follows from The #include directive. Your First Program #include int main(){ printf("Hello World!\n"); return 0; }

H.Melikian The main Function v A FUNCTION can be thought of a set of instructions that is carried out when it is CALLED. v All C programs must have a main function. You can only have one, but you can place it anywhere within the code. v The program always start with the main function and ends when the end of main is reached. Functions return a value too - this will be explained later. v If a function returns nothing, it's return type is of type void – v The main function is special, as it returns an integer by default, which is why you'll see me write return 0.

H.Melikian Constants and Variables v Variables are like containers in your computer's memory - you can store values in them and retrieve or modify them when necessary. v Constants are like variables, but once a valued is stored (i.e. the constant is INITIALIZED), its value cannot be change v There are several rules that you must follow when naming variables:

H.Melikian Do no forget Variable names.... v CANNOT start with a number 2times v CAN contain a number elsewhere times2 v CANNOT contain any arithmetic operators... a*b+c v... or any other pun ctuation marks... v... but may contain or begin with an underscore _height v CANNOT be a C keyword while v CANNOT contain a space stupid me v CAN be of mixed cases HaykMelik

H.Melikian Some Terminology v EXPRESSIONS consist of a mixture of constants, variables and operators (more about operators later). They return values. 17 /* a constant */ x /* a variable */ x + 17 /* a variable plus a constant */ v STATEMENTS are instructions and are terminated with a semicolon,;. x = 1 + 8; printf("We will learn printf soon!\n"); int x, y, z; /* more on "int" later */ v STATEMENT BLOCKS, on the other hand, can contain a group of statements

H.Melikian Example v STATEMENT BLOCKS, on the other hand, can contain a group of statements if(x==10) { /* block 1 */ printf("x equals 10\n"); x = 11; printf("Now x equals 11\n"); x = x + 1; printf("Now x equals 12\n"); } /* end of block 1 */ else { /* block 2 */ printf("x not equal to 10\n"); printf("Good bye!\n"); } /* end of block 2 */

H.Melikian Types of Constants Numbers are considered as LITERAL constants – you can't change the number 20, nor can you assign something else into 20. v On the other hand, SYMBOLIC constants can be assigned a v value during initialization and are represented by a word. const int radius = 5; v There are several ways to define constants in C. Later, we will meet the #define directive and the enum keyword – two more ways of defining constants.

H.Melikian

HW #4 Readig: LAB: Homework: Assigned Due 09/23/02 PS. To submit you have to use the fallowing command % mail melikian< typescript

H.Melikian Life Cycle

H.Melikian input

H.Melikian compiler