C Syntax Out: 15 September, 1995

Similar documents
Review of the C Programming Language for Principles of Operating Systems

DEPARTMENT OF MATHS, MJ COLLEGE

EL6483: Brief Overview of C Programming Language

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Review of the C Programming Language

UNIT- 3 Introduction to C++

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

C: How to Program. Week /Mar/05

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

A Fast Review of C Essentials Part I

Chapter 2 - Introduction to C Programming

Fundamental of Programming (C)

A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

Introduction to Programming Using Java (98-388)

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

8. Control statements

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

INTRODUCTION 1 AND REVIEW

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

CSCI 171 Chapter Outlines

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan



Lectures 5-6: Introduction to C

UNIT-2 Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Introduction to C++

Computer Organization & Systems Exam I Example Questions

Princeton University COS 333: Advanced Programming Techniques A Subset of C90

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

M4.1-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Flow Control. CSC215 Lecture

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Course Outline Introduction to C-Programming

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

.. Cal Poly CPE 101: Fundamentals of Computer Science I Alexander Dekhtyar..

C Programming Review CSC 4320/6320

BLM2031 Structured Programming. Zeyneb KURT

ME 461 C review Session Fall 2009 S. Keres

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

C Language Summary. Chris J Michael 28 August CSC 4103 Operating Systems Fall 2008 Lecture 2 C Summary

Programming and Data Structures

Variables. Data Types.

UNIT IV 2 MARKS. ( Word to PDF Converter - Unregistered ) FUNDAMENTALS OF COMPUTING & COMPUTER PROGRAMMING

COMP322 - Introduction to C++ Lecture 02 - Basics of C++

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

SEQUENTIAL STRUCTURE. Erkut ERDEM Hacettepe University October 2010

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CMPT 115. C tutorial for students who took 111 in Java. University of Saskatchewan. Mark G. Eramian, Ian McQuillan CMPT 115 1/32

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

C Programming Language (Chapter 2 of K&R) Variables and Constants

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

ET156 Introduction to C Programming

We do not teach programming

Input And Output of C++

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

CS 61C: Great Ideas in Computer Architecture Introduction to C

Information Science 1

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

Syntax and Variables

C library = Header files + Reserved words + main method

Creating a C++ Program

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

Lecture 2: C Programming Basic

AN OVERVIEW OF C, PART 3. CSE 130: Introduction to Programming in C Stony Brook University

IV Unit Second Part STRUCTURES

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

C Programming Class I

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

CSc Introduction to Computing

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

The C Programming Language Guide for the Robot Course work Module

ANSI C Programming Simple Programs

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

In Java, data type boolean is used to represent Boolean data. Each boolean constant or variable can contain one of two values: true or false.

Full file at C How to Program, 6/e Multiple Choice Test Bank

XSEDE Scholars Program Introduction to C Programming. John Lockman III June 7 th, 2012

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Have examined process Creating program Have developed program Written in C Source code

Chapter 1 & 2 Introduction to C Language

Fundamentals of Programming

Data Types and Variables in C language

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

C - Basics, Bitwise Operator. Zhaoguo Wang

The following expression causes a divide by zero error:

YOLOP Language Reference Manual

Programming in C and Data Structures [15PCD13/23] 1. PROGRAMMING IN C AND DATA STRUCTURES [As per Choice Based Credit System (CBCS) scheme]

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report

Computer Programming : C++

Computer Programming CS F111

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

APPENDIX A : Example Standard <--Prev page Next page -->

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

Transcription:

Burt Rosenberg

Math 220/317: Programming II/Data Structures 1 C Syntax Out: 15 September, 1995 Constants. Integer such as 1, 0, 14, 0x0A. Characters such as A, B, \0. Strings such as "Hello World!\n", "A". Variables, such as u, i, u_and_i_are_variables. Expressions. Constants and variables are expressions. So are expressions connected together by operators and using parentheses to group operators. The operators are: Arithmetic: +, -, *, /, % and unary - meaning negative. Assignment: =, +=, -=, *=, &=, =, ++, -- Access: access an array element, [ ], access a structure element,. or ->, call a function, ( ), access the target of a pointer, *. Logical: ==,!=, <, <=, >, >=, &&,,! Bitwise: &,, <<, >>, ~, ^ Utility: the cast ( ), the address operator & and the sizeof operator. x+1, (x+1), (1+3), x=((y+z)>2)+1, (*x[100]).field, f(1) Statements. Expressions followed by a semicolon are statements, such as x=y+1; Compound Statements: a series of declarations, perhaps none, followed by series of statements, perhaps none, all enclosed in a pair of curly braces. x=1; y=2;, int i; i=1;,, ; The If Statement: if ( Expr ) Statement if (x>y) x=y+1; if ((x+1)==y) x=1; y=2; The If-Else Statement: if ( Expr ) Statement else Statement if (x>y) x=y+1; else x=1; y=2; if ((x+1)==y) x=1; y=2; else x=y+1; if (x=(y>1)) x++ ; else y-- ; if (x==y) x=2; y=3; else x=3; y=2 if (x==y) ; else do_only_me++ The While Statement: while ( Expr ) Statement while (a>0) a-- ; while ( ++a<100 ) ;

Math 220/317: Programming II/Data Structures 2 The For Statement: for ( Expr1 ; Expr2 ; Expr3 ) Statement Note: This statement is equivalent to Expr1 ; while (Expr2) Statement Expr3; for(i=0;i<10;i++) a[i]=0 ; The Switch Statement: switch (Expr) Compound-Statement, where the Compound Statement generally has case-labeled lines: case Expr: Statement, and the special default: Statment. Example: switch( string[0] ) case y : printf("yes\n") ; break ; case n : printf("no\n") ; break ; default: printf("string[0] is neither y nor n\n") ; Other statements include the Break: break;, the Continue: continue;, the Return of two forms: return with value: return(expr);, return without value: return;, the Conditional Evaluation: ( Expr1 )? Expr2 : Expr3 ;, and the Null: ;. Declarations. These are allowed as the first elements of a compound statement or at the outermost level of the file (outside of all curly braces). They are of the form: storage-class type name-list ;. Storage-class: extern, static, typedef are the most frequently used. Types: char, int and double are the most frequently used, as well as a structure specifier or a typedef name. Less frequently used are float, unsigned char, unsigned long, and a union specifier. Name-list: a comma separated list of possibly initialized declarators of the following kinds: identifier, pointer, function or array. Parenthesis are used to nest declarators, forming very complex types. identifier: a name. pointer: * followed by a declarator or name. function: a declarator or name followed by () array: a declarator or name followed by [optional-integer], where the optional integer constant indicates the size of the array. Structure specifier: we come back to talk about these here because they are complicated. These are of new main forms To declare new structure type: struct optional-structure-tag declarations The declarations are a sequence of declarations exactly as described by the section, except that the storage-class tags do not apply. To recall a defined structure type: stuct structure-tag.

Math 220/317: Programming II/Data Structures 3 Typedef: The storage class typedef declares a name for a new type. Write the declaration as if you were defining a variable, however the storage class typedef will assign to the variable the resulting type, which can then be used in further declarations. int i ; int i, j; int *pntr_i ; int i, *pntr_i ; double x[100] ; double y, x[100], *pntr ; char *array_of_10_pntrs_to_char[10] ; char (*Pntr_to_an_array_of_10_char)[10] ; struct int i, j a_struct, another_struct ; struct S int i ; double x ; Array_of_S[10], *Pntr_to_S ; struct S yet_another_s_struct, ten_more_such[10] ; typedef LITTLE_ARRAY[10]; LITTLE_ARRAY i_am_an_array ; Function Definition. These are allowed only at the outermost level of the program file. A function named main is special: there must be one and only one such function for each program. The syntax is function-declaration(prototype) function-body. Function Declaration with prototype: Use the declaration syntax to give the name and return type of the function, and within the parentheses, give a comma separated list of declarations giving the name and types of the arguments. The storage class is ignored for arguments, and only the classes extern and static are generally used for the function itself. In the case of functions static means a function private to the current file and extern means a function whose name is exported to other files in a project. Function Body: A compound statement. int f(int i) return(i) ; int g( int a[], int n ) int j, sum ; sum = 0 ; for ( j=0;j<n;j++ ) sum+= a[j] ; return(sum) ; char * h(char * s) while (*s!=\ 0 ) if (*s==, ) break ; s++ ; return(s) ; /* a pointer to a character, not *s! */

Math 220/317: Programming II/Data Structures 4 Preprocessor. #include: Read in text from the named file. If enclosed in double quotes, the file name is used exactly. If enclosed in pointy brackets, the include file is looked for in the location of system wide include files. The preprocessor is not the compiler an ending semicolon is not used. #include<stdio.h> #include "myheaderfile.h" #define: Makes the first word that follows an alias for the rest of the line. Macros are also created using define. #define PI 3.14159 #define TRUE 0==0 Conditional Compilation: These controls are used for making C code that compiles on many different platforms, using code pieces that adapt to the system s configuration. I mention them here because they are useful for commenting out large blocks of code when debugging. In C, comments of the /* */ type cannot be nested. Instead, use: #if 0 The compiler will skip over all of this because what follows the #if is value 0. The compiler begins again after the #endif... #endif