An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.

Slides:



Advertisements
Similar presentations
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Advertisements

ARDUINO CLUB Session 1: C & An Introduction to Linux.
C Programming Day 1 based upon Practical C Programming by Steve Oualline CS550 Operating Systems.
Lecture 2 Introduction to C Programming
Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Primitive Variable types Basic types –char (single character or ASCII integer value) –int (integer) –short (not longer than int) –long (longer than int)
Unix Continuum of Tools Do something once: use the command line Do something many times: –Use an alias –Use a shell script Do something that is complex.
Lecture 1 The Basics (Review of Familiar Topics).
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Computer Science 210 Computer Organization Introduction to C.
CS 11 C track: lecture 1 Preliminaries Need a CS cluster account cgi-bin/sysadmin/account_request.cgi Need to know UNIX ITS.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
#include int main(void) { printf("Hello, world!\n"); return 0; } entry point called on program start only one main( ) in any program # for preprocessor.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
1 Programming Java Java Basics. 2 Java Program Java Application Program Application Program written in general programming language Applet Program running.
Introduction to Java Java Translation Program Structure
Introduction to Programming
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
Selection-making Decisions Selection allows you to choose between two or more possible program flow --- it lets you make decisions in your program. Examples.
Khalid Rasheed Shaikh Computer Programming Theory 1.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
ICT Introduction to Programming Chapter 4 – Control Structures I.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
C is a high level language (HLL)
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
1 2. Program Construction in Java. 01 Java basics.
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.
Midterm preview.
Basic concepts of C++ Presented by Prof. Satyajit De
The Machine Model Memory
Computer Science 210 Computer Organization
- Standard C Statements
Chapter 2 - Introduction to C Programming
Lecture 7: Repeating a Known Number of Times
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Chapter 2 - Introduction to C Programming
Chapter 3: Understanding C# Language Fundamentals
Computer Science 210 Computer Organization
Arrays, For loop While loop Do while loop
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C Topics Compilation Using the gcc Compiler
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Chapter 2 - Introduction to C Programming
elementary programming
C Programming Getting started Variables Basic C operators Conditionals
Introduction to C Topics Compilation Using the gcc Compiler
Chapter 2 - Introduction to C Programming
Programming Languages and Paradigms
An Overview of C.
Dale Roberts, Lecturer IUPUI
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Introduction to C Programming
Presentation transcript:

An Introduction to C Programming Geb Thomas

Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the C variable types Understand how to use if and if/else statements Understand how to use the for structure

How to Write and Compile C Programs C, C++ and Java Compilers: Microsoft Visual C++, GCC, Borland C Since we will be working on PCs: Microsoft Visual C++ Open new Win32 Console Application Name it (in “project name”) Click “a hello world application” Go to file view, source files, then the name of your project.cpp

Some Things About C Case matters, white space does not Comments go between /* and */ Each statement is followed by a semicolon Execution begins in the main function: int main(int argc, char* argv[]) { /* ignore this */ /* start here */ return 0; /*end here */ }

What are C libraries? C is a lightweight language. Most of its intelligence is compartmentalized in libraries. Almost all c programs use the “stdio” or standard input/output library. Many also use the “math” library. To use a library, include the header file (I.e., “stdio.h”) at the top of the file. For most special purpose libraries (I.e., math) you need to include the library on the link line. In Visual C++, go to project->settings- >object/module libraries.

C Variable Types The most common types are: char, int, float, and double. Strings are arrays of characters (we’ll cover arrays later). Declare a variable before you use it: int x; /* declares an integer called x. Its value is not assigned. */ float y, z = ; /* declares two floating point numbers. z is set equal to pi */ z = 4; /* now z is equal to 4 */ myVal = 2; /* This would be an error, because myVal was not yet declared */

Logical Operators C defines these logical operators:, = and == (the equivalence operator) You can compare any variable. Characters are compared based on their ASCII values. All answers will be true (not zero) or false (0) You can extend the logic with && (and), ~ (not) and || (or).

The If Statement Syntax: if (expression) statement; If the expression is true (not zero), the statement is executed. If the expression is false, it is not executed. You can group multiple expressions together with braces: if (expression) { statement 1; statement 2; statement 3; }

The If/Else Statement Syntax: if (expression) statement_1; else statement_2; If the expression is true, statement_1 will be executed, otherwise, statement_2 will be. if (myVal < 3) printf(“myVal is less than 3.\n”); else printf(“myVal is greater than or equal to 3.\n”);

The For Loop Syntax: for (initialization; test; increment) {statements;} The for loop will first perform the initialization. Then, as long is test is TRUE, it will execute statements. After each execution, it will increment. for (cntr = 0; cntr < 3; cntr = cntr + 1) { printf(“ Counter = %d\n”, cntr); } Counter = 0; Counter = 1; Counter = 2;

Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the C variable types Understand how to use if and if/else statements Understand how to use the for structure