C PROGRAMMING LECTURE 17 th August IIT Kanpur C Course, Programming club, Fall 2008 1 by Deepak Majeti M-Tech CSE

Slides:



Advertisements
Similar presentations
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Advertisements

C Language.
ARDUINO CLUB Session 1: C & An Introduction to Linux.
Programming In C++ Spring Semester 2013 Lecture 2 Programming In C++, Lecture 2.
Lecture 2 Introduction to C Programming
Introduction to C Programming
Outline 2.1 Introduction 2.2 Basics of C Programs
Dale Roberts Basic I/O – scanf() CSCI 230 Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Department of.
ספטמבר 04Copyright Meir Kalech1 C programming Language Chapter 1: Types, Operators and Expressions.
C programming.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
The little language that could Remember C is a “small language”
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Basic Input/Output and Variables Ethan Cerami New York
C PROGRAMMING LECTURE C-language Computer Fundamentals.
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
Introduction to C Language
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
 Input and Output Functions Input and Output Functions  OperatorsOperators Arithmetic Operators Assignment Operators Relational Operators Logical Operators.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Numeric Types, Expressions, and Output ROBERT REAVES.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
Beginning C++ Through Game Programming, Second Edition
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
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 Simple Data Types By C. Shing ITEC Dept Radford University.
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Khalid Rasheed Shaikh Computer Programming Theory 1.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Variables Symbol representing a place to store information
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
Lecture 2. Outline Sample programming question Sample C program Identifiers and reserve words Program comments Preprocessor directives Data types and.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CSE 1320 Basics Dr. Sajib Datta
Powerpoint Templates Page 1 Programming in C/C++ PS04CINS02.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
C Building Block Chapter 2. Variables A variable is a space in the computer’s memory set aside for a certain kind of data and given a name for easy reference.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
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.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
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.
A bit of C programming Lecture 3 Uli Raich.
INC 161 , CPE 100 Computer Programming
Introduction to C Programming
Administrative things
Visit for more Learning Resources
Lexical Elements, Operators, and the C Cystem
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Lexical Elements, Operators, and the C Cystem
Introduction to C Programming
Conversion Check your class notes and given examples at class.
Lecture3.
Introduction to Java Applications
Introduction to C Programming
Module 2 Variables, Data Types and Arithmetic
Variables in C Topics Naming Variables Declaring Variables
EECE.2160 ECE Application Programming
DATA TYPES There are four basic data types associated with variables:
Course Outcomes of Programming In C (PIC) (17212, C203):
Introduction to C Programming
Introduction to C Programming
Presentation transcript:

C PROGRAMMING LECTURE 17 th August IIT Kanpur C Course, Programming club, Fall by Deepak Majeti M-Tech CSE

Recap C Course, Programming club, Fall  C is a high-level language.  Writing a C code. {editors like gedit, vi}  Compiling a C code. {gcc –c test.c –o test}  Executing the object code. {./test}

Some more basics C Course, Programming club, Fall  Keywords char, static, if, while, return Total= about 32  Data Types int, char, float...………..….. Some more later  Arithmetic Operators + (Plus), - (Minus), * (Multiplication), /(Division) ……….…… …. Some more later

My first C program! C Course, Programming club, Fall #include // program prints hello world int main() { printf ("Hello world!"); return 0; } Output: Hello world!

Example 1 C Course, Programming club, Fall #include // program prints a number of type int int main() { int number = 4; printf (“Number is %d”, number); return 0; } Output: Number is 4

Example 2 C Course, Programming club, Fall #include // program reads and prints the same thing int main() { int number ; printf (“ Enter a Number: ”); scanf (“%d”, &number); printf (“Number is %d\n”, number); return 0; } Output : Enter a number: 4 Number is 4

more and more C Course, Programming club, Fall #include int main() { /* this program adds two numbers */ int a = 4; //first number int b = 5; //second number int answer = 0; //result answer = a + b; }

Note C Course, Programming club, Fall Errors Compilation Compiler generally gives the line number at which the error is present. Run time C programs are sequential making the debugging easier.

Some more Data Types C Course, Programming club, Fall  Primary : int, float, char  int (signed/unsigned)(2,4Bytes): used to store integers.  char (signed/unsigned)(1Byte): used to store characters  float, double(4,8Bytes): used to store a decimal number.  User Defined:  typedef: used to rename a data type typedef int integer; can use integer to declare an int.  enum, struct, union

Some more Arithmetic Operators C Course, Programming club, Fall  Prefix Increment : ++a  example: int a=5; b=++a; // value of b=6; a=6;  Postfix Increment: a++  example int a=5; b=a++; //value of b=5; a=6;

Contd… C Course, Programming club, Fall  Modulus (remainder): %  example: 12%5 = 2;  Assignment by addition: +=  example: int a=4; a+=1; //(means a=a+1) value of a becomes 5 Can use -, /, *, % also

Contd… C Course, Programming club, Fall  Comparision Operators:, =, !=, ==, !, &&, ||.  example: int a=4, b=5; a<b returns a true(non zero number) value.  Bitwise Operators: >, ~, &, |,^.  example int a=8; a= a>>1; // value of a becomes 4

Operator Precedence C Course, Programming club, Fall  Meaning of a + b * c ? is it a+(b*c) or (a+b)*c ?  All operators have precedence over each other  *, / have more precedence over +, -.  If both *, / are used, associativity comes into picture. (more on this later)  example : 5+4*3 = 5+12= 17.

Precedence Table C Course, Programming club, Fall Highest on top (Postfix) (Prefix) * / % + - > & | && ||

Input / Output C Course, Programming club, Fall  printf (); //used to print to console(screen)  scanf (); //used to take an input from console(user).  example: printf(“%c”, ’a’); scanf(“%d”, &a);  More format specifiers %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.

Some more geek stuff C Course, Programming club, Fall  & in scanf.  It is used to access the address of the variable used.  example: scanf(%d,&a); we are reading into the address of a.  Data Hierarchy.  example: int value can be assigned to float not vice-versa. Type casting.

Home Work C Course, Programming club, Fall  Meaning of  Syntax  Semantics of a programming language  Find the Output:  value=value++ + value++;  Value=++value + ++value;  value=value value;

End of Today’s Lecture C Course, Programming club, Fall Doubts && Queries?

THANK YOU C Course, Programming club, Fall