Introduction to C Programming

Slides:



Advertisements
Similar presentations
11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Introduction to C Programming
Principles of Programming Fundamental of C Programming Language and Basic Input/Output Function 1.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Introduction to C Programming
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 Getting Started in C Programming
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
/* Documentations */ Pre process / Linking statements Global declarations; main( ) { Local Declarations; Program statements / Executable statements; }
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Chapter 2 part #1 C++ Program Structure
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© 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.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
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.
C Formatted Input/Output
CSCE 206 Structured Programming in C
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CSC201: Computer Programming
Chapter 2 - Introduction to C Programming
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
TMF1414 Introduction to Programming
Revision Lecture
Introduction to Scripting
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Chapter 2 Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Variables & Data types Selection Statements Additional Operators
Structured Program Development in C
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Introduction to Java Applications
Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Structured Program Development in C
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 2 part #1 C++ Program Structure
Data Types and Arithmetic in C
Presentation transcript:

Introduction to C Programming 12/12/2019 Introduction to C Programming Created by :Dr. Nouf Aljaffan Edited by : Nouf almunyif Nouf Aljaffan (C) 2018

Objectives Write simple C programs. Use simple input and output statements. Use the fundamental data types. Learn computer memory concepts. Use arithmetic operators. Learn the precedence of arithmetic operators. Write simple decision making statements. Begin focusing on secure C programming practices

Structure of a .c file Add Comments Insert pre-processor definitions 12/12/2019 Structure of a .c file Add Comments Line comment: // my comment multi-line comments : /* my comments */ Insert pre-processor definitions #include < [file name & extension] > Add function prototypes and variable declarations Define main function int main( void ) { [function body] } Define other functions Nouf Aljaffan (C) 2018

Comments begin with //. Comments document programs and improve program readability

Header contains information used by the compiler when compiling calls to standard input/output library functions such as printf.

The function main is a part of every C program. The parentheses after main indicate that main is a program building block called a function C programs contain one or more functions, one of which must be main. Every program in C begins executing at the function main.

Functions can return information Functions can return information. The keyword int to the left of main indicates that main “returns” an integer (whole-number) value.

Functions can receive information when they’re called upon to execute Functions can receive information when they’re called upon to execute. The void in parentheses after main indicates that main does not receive any information.

A left brace, {, begins the body of every function A corresponding right brace, }, ends each function . This pair of braces and the portion of the program between the braces is called a block.

The printf function instructs the computer to display information on the screen. • A string is sometimes called a character string, a message or a literal

Every statement must end with a semicolon

Structure of a .c file the backslash (\) is called an escape character 12/12/2019 Structure of a .c file the backslash (\) is called an escape character When encountering a backslash in a string, the compiler looks ahead at the next character and combines it with the backslash to form an escape sequence The escape sequence \n means newline Nouf Aljaffan (C) 2018

12/12/2019 Structure of a .c file Nouf Aljaffan (C) 2018

Multiple printf

Avoid Single-Argument printf If you need to display a string that terminates with a newline, use the puts function, If you need to display a string without a terminating newline character, use printf with two arguments—a "%s" format control string and the string to display.

Variables and DataTypes

Variables/Identifiers Names that represent values in the program Similar to algebraic variables All variables have a type which must be declared E.g. int x; float y; Type determines : how arithmetic is preformed, how much memory space is required. Variables/Identifiers

Data types and sizes C has a small family of datatypes. Numeric (int, float, double) Character (char) User defined (struct,union)

Basic Data Types The individual sizes are machine/compiler dependent. However, the following is guaranteed: sizeof(char)<sizeof(short)<=sizeof(int)<=sizeof(long) sizeof(char)<sizeof(short)<=sizeof(float)<=sizeof(double)

Variables and Variable Definitions Naming rules: Variable names can contain letters,digits and _ Variable names should start with letters. Keywords (e.g., for,while etc.) cannot be used as variable names Variable names are case sensitive. int x; int X declares two different variables.

Pop quiz (correct/incorrect): int money$owed; int total_count int score2 int 2ndscore int long

Variable declaration The general format for a declaration is Type variable name [=value] ; char x; /∗ uninitialized ∗/ char x=’A’; /∗ intialized to ’A’∗/ char x=’A’,y=’B’; /∗multiple variables initialized ∗/ char x=y=’Z’; /∗multiple initializations ∗/

Input / Output More format specifiers printf (); //used to print to console(screen) example: printf(“%c”, ’a’); scanf (); //used to take an input from console(user). example: scanf(“%d”, &a); %c     The character format specifier. %d     The integer format specifier. %i     The integer format specifier (same as %d). %f     The floating-point format specifier. %o     The unsigned octal format specifier. %s     The string format specifier. %u     The unsigned integer format specifier. %x     The unsigned hexadecimal format specifier. %%     Outputs a percent sign.

Output: If you need to display a string on the screen

Input: if you want to read values from the user

Declaring different types

output

Any Question!