‘C’ Programming Structures and Commands

Slides:



Advertisements
Similar presentations
C Language.
Advertisements

Structure of a C program
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Computer Science 210 Computer Organization Introduction to C.
Yu Yuanming CSCI2100B Data Structures Tutorial 3
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
Intro to Programming in C. Motivation for Using C  High level, compiler language  Efficiency over user-friendliness  Allows programmer greater freedom,
Structure of a C program Preprocessor directive (header file) Program statement } Preprocessor directive Global variable declaration Comments Local variable.
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.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Lecture 1 cis208 January 14 rd, Compiling %> gcc helloworld.c returns a.out %> gcc –o helloworld helloworld.c returns helloworld.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
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;
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
NOTE: C programs consist of functions one of which must be main. C programs consist of functions one of which must be main. Every C program begins executing.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
BASIC C PROGRAMMING LANGUAGE TUTORIAL infobizzs.com.
C Language Elements Preprocessor Directives # (sign for preprocessor directive commands) #include Standard header file (.h) Library.
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.
Numbers in ‘C’ Two general categories: Integers Floats
Arithmetic Expressions
Chapter Topics The Basics of a C++ Program Data Types
Computer Science 210 Computer Organization
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
A bit of C programming Lecture 3 Uli Raich.
Functions, Part 2 of 2 Topics Functions That Return a Value
C Programming Tutorial – Part I
Basic Elements of C++.
C Language By Sra Sontisirikit
Day 02 Introduction to C.
Chapter 18 I/O in C.
C Fundamentals & Pointers
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C Short Overview Lembit Jürimägi.
Module 2 Arrays and strings – example programs.
Introduction to C Programming Language
' C ' PROGRAMMING SRM-MCA.
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
DATA HANDLING.
Basic Elements of C++ Chapter 2.
Visit for more Learning Resources
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
C Stuff CS 2308.
Variables in C Topics Naming Variables Declaring Variables
Functions, Part 2 of 3 Topics Functions That Return a Value
Govt. Polytechnic,Dhangar
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.
Govt. Polytechnic,Dhangar
WEEK-2.
The C Language: Intro.
Programming Languages and Paradigms
Variables in C Topics Naming Variables Declaring Variables
DATA TYPES There are four basic data types associated with variables:
Variables in C Topics Naming Variables Declaring Variables
Course Outcomes of Programming In C (PIC) (17212, C203):
C Characters and Strings
Variables in C Topics Naming Variables Declaring Variables
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
CPS125.
INTRODUCTION TO C.
Variables in C Topics Naming Variables Declaring Variables
COMP 2130 Intro Computer Systems Thompson Rivers University
Presentation transcript:

‘C’ Programming Structures and Commands By Aradhya Malhotra

Background C is a general purpose programming language that was founded in 1972 by Dennis Ritchie Unlike previously developed languages C provides facilities for structured programming and allows lexical variable scope and recursion It is the predecessor to C++ but and does not support the Object Oriented Programming Style (OOPS) paradigm

Structure of C C programs basically contains the following: Preprocessor Commands Variables Constants Input/output Functions

Preprocessor commands The #include pre-processor directive is used to link required library files to the main program file (.cpp) Some of the common header files and their functions are as follows: Stdio.h : Standard input /output functions Math.h: Basic math functions such as tan, log, pow(x,y) etc. String.h: String operations such as strcpy, strcat etc. Stlib.h: Standard functions such as malloc, rand, srand etc. Ctype.h: Character classification functions such as isalnum, isalpha, isdigit etc. Iso646.h: To use macros for logical operators E.g. #include<stdio.h> void main() { int x; scanf(“%d”,x); //needs the stdio.h header file }

Variables – Data types In C, variables can be broadly of the following data types: char – character type char stringname [x] (x=1,2..n)- string of ‘x’ characters int array [x] – array containing ‘x’ elements int- integer type float- real numbers including decimals etc. double- extended form of float (larger range) The above can also be used in conjunction with the following ‘datatype’ modifiers: long short signed unsigned cont…

Variables – Data types cont... In addition to the previously described standard datatypes, C allows the following user defined datatypes: typedef- Allows users to change the name of a standard data type. For e.g. typedef float money will allow the user to use money as a data type enum- Enumerated data types similar to C++ e.g. enum color{red,blue,white} struct- Structures are heterogeneous user-defined datatypes They are often used to create nodes and lists They are like the data members of classes but do not have the concept of associated functions ` e.g. struct features{ int height; double weight; char[5] color; }

Constants In C, constants can be defined in the following two ways- Using #define e.g. #define pi 3.14 Using const e.g. const double x=3.0 Constants are often declared globally instead of being used directly in the main program

Input / Output User input from the keyboard is done using ‘scanf ‘ Output to the screen is done using ‘printf’ Here are the format specifiers that are required %d - int %c - char %f - float %lf -double %s -string %x- hexadecimal For e.g. #include<stdio.h> void main() { int x; scanf(“Enter integer: %d”,x); printf(“The integer you entered is: %d,x,”. Goodbye!”); }

Functions Functions are modules or subprograms that accept certain parameters and return values to the calling function / main program They have the following format: Return_type function_name(parameters) { local variables; C statements; return return_value; }

Additional Concepts Operators and Expressions Arrays Linked Lists Pointers Stacks and Queues Hash Tables