By Sidhant Garg.  C was developed between 1969-1973 by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

C Language.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Chapter 4 Function By C. Shing ITEC Dept Radford University.
1 CS 161 Introduction to Programming and Problem Solving Chapter 9 C++ Program Components Herbert G. Mayer, PSU Status 10/20/2014.
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?
Guide To UNIX Using Linux Third Edition
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C Programming. Chapter – 1 Introduction Study Book for one month – 25% Learning rate Use Compiler for one month – 60%
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.
1 COMP 2130 Introduction to Computer Systems Computing Science Thompson Rivers University.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
(1 - 2) C Language Elements H&K Chapter 2 Instructor - Andrew S. O’Fallon CptS 121 (August 28, 2015) Washington State University.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Programming I Introduction Introduction The only way to learn a new programming language is by writing programs in it. The first program to.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
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.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
Introduction to Programming
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;
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Prof. Béat Hirsbrunner Ammar Halabi, PhD student (exercises) Dani Rotzetter, Master student (exercises) Bachelor students : Major in computer science (3rd.
Introduction to Computer Organization & Systems Topics: Types in C: floating point COMP C Part III.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
C LANGUAGE Characteristics of C · Small size
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.
Computer Programming for Engineers
A.Abhari CPS1251 Topic 2: C Overview C Language Elements Variable Declaration and Data Types Statement Execution C Program Layout Formatting Output Interactive.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
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.
BASIC C PROGRAMMING LANGUAGE TUTORIAL infobizzs.com.
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
‘C’ Programming Structures and Commands
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
C Fundamentals & Pointers
Getting Started with C.
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C Short Overview Lembit Jürimägi.
Introduction to C Programming Language
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Visit for more Learning Resources
Computer Science 210 Computer Organization
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.
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.
C – Programming Language
Programming Languages and Paradigms
Variables in C Topics Naming Variables Declaring Variables
Course Outcomes of Programming In C (PIC) (17212, C203):
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

By Sidhant Garg

 C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously developed languages C provides facilities for structured programming and allows lexical variable scope and recursion  C is one of the most popular programming languages and there are a very few computer architecture for which the C compiler does not exist.

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

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 void main() { int x; scanf(“%d”,x); //needs the stdio.h header file }

 #include  /* print Fahrenheit-Celsius table  for fahr = 0, 20,..., 300 */  main()  {  int fahr, celsius;  int lower, upper, step;  lower = 0; /* lower limit of temperature scale */  upper = 300; /* upper limit */  step = 20; /* step size */  fahr = lower;  while (fahr <= upper) {  celsius = 5 * (fahr-32) / 9;  printf("%d\t%d\n", fahr, celsius);  fahr = fahr + step;  }

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…

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; }

 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.

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 void main() { int x; scanf(“Enter integer: %d”,x); printf(“The integer you entered is: %d,x,”. Goodbye!”); }

 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; }

 In C all the function arguments are passed by value. This means that the functions are given the values of it arguments in temporary variable rather than the originals.  It usually leads to more compact programs with fewer extraneous variables, because parameters can be treated as conveniently initialized local variables in the called routine

For example, here is a version of power that makes use of this property. /* power: raise base to n-th power; n >= 0; version 2 */ int power(int base, int n) { int p; for (p = 1; n > 0; --n) p = p * base; return p; } The parameter n is used as a temporary variable, and is counted down (a for loop that runs backwards) until it becomes zero; there is no longer a need for the variable i. Whatever is done to n inside power has no effect on the argument that power was originally called with.

 Operators and Expressions  Arrays  Linked Lists  Pointers  Stacks and Queues  Hash Tables