Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.

Slides:



Advertisements
Similar presentations
Outline 2.1 Introduction 2.2 Basics of C Programs
Advertisements

1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Structure of a C program
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Data types and variables
C programming Language and Data Structure For DIT Students.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Copyrights© 2008 BVU Amplify DITM Software Engineering & Case Tools Page:1 INTRODUCTION TO ‘C’ LANGUAGE Chapter 2.
Chapter 2 Getting Started in C Programming
A First Book of ANSI C Fourth Edition
Chapter 2: C Fundamentals Dr. Ameer Ali. Overview C Character set Identifiers and Keywords Data Types Constants Variables and Arrays Declarations Expressions.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
2440: 211 Interactive Web Programming Expressions & Operators.
C Programming Lecture 4 : Variables , Data Types
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
Five Tips to Success. Work hard Try more exercises and more practice.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
1 CSC103: Introduction to Computer and Programming Lecture No 6.
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Week 1 Algorithmization and Programming Languages.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Chapter 3: Formatted Input/Output Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
What is C? C is a programming language. It was developed in 1972 USA. It was designed and written by a man named dennis ritchie. C is the base for all.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
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.
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
Chapter 3: Formatted Input/Output 1 Chapter 3 Formatted Input/Output.
Constants, Data Types and Variables
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
INTRODUCTION TO C LANGUAGE
Lecture2.
Numbers in ‘C’ Two general categories: Integers Floats
Introduction to ‘c’ language
BASIC ELEMENTS OF A COMPUTER PROGRAM
Tokens in C Keywords Identifiers Constants
Wel come.
ICS103 Programming in C Lecture 3: Introduction to C (2)
' C ' PROGRAMMING SRM-MCA.
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++ Basics.
2.1 Parts of a C++ Program.
Basics of ‘C’.
CS111 Computer Programming
Lecture3.
C programming Language
WEEK-2.
Lexical Elements & Operators
DATA TYPES There are four basic data types associated with variables:
Introduction to C Programming
Presentation transcript:

Constants, Variables and Data types in C

The C character Set A character denotes any alphabet, digit or special symbol used to represent information. Alphabets A,B, ….,Y, Z a,b, …..,y, z Digits 0,1,2,3,4,5,6,7,8,9 Special Symbols ~ ‘ # % ^ & * ( ) _ - + = | \ { } [ ] : ; “ ‘,. ? /

Identifiers Identifiers are names given to various program elements, such as variables, functions and arrays A variable name is any combination of alphabets, digits or underscores The first character in the variable name must be an alphabet

Variable It is a data name which is used to store data and may change during program execution. It is opposite to constant. Variable name is a name given to memory cells location of a computer where data is stored. * Rules for varibales: First character should be letter or alphabet. Keywords are not allowed to use as a variable name. White space is not allowed. C is case sensitive i.e. UPPER and lower case are significant. Only underscore, special symbol is allowed between two characters. The length of indentifier may be upto 31 characters but only only the first 8 characters are significant by compiler.

Types of C Constants C constants can be divided into two major categories Primary Constants Secondary Constants C Constants Primary ConstantsSecondary constants Integer Constant Real Constant Character Constant Array, Pointer Structure, Union Enum

Integer Constants An integer constant must have at least one digit It must not have a decimal point It could be either positive or negative If no sign precedes an integer constant, it is assumed to be positive No commas or blanks are allowed within an integer constant 1990, 194, -394

Real Constants Real constants(RC) must have at least one digit It must have a decimal point It could be either positive or negative Default sign is positive No commas or blank are allowed within a RC ,

Character Constants A character constant is either a single alphabet, a single digit or a single special symbol enclosed within single inverted commas The maximum length of a character constant can be 1 character Eg ‘a’, ‘1’, ‘5’, ‘=‘ (Valid) ‘asd’, ‘12’ (Invalid)

String Constants A String Constant consists of any number consecutive characters enclosed in double quotation marks Escape sequence can be embedded within the string.

Keywords Keywords are the words whose meaning has already been explained to the C compiler They cannot be used as variable names. There are only 32 keywords available in c autodoubleifstaticdo breakelseintstructgoto caseenumlongswitchsigned charexternneartypedefwhile constfloatregisteruniondefault continuefarreturnunsignedfor shortvoid

C Instructions There are basically four types of instructions in C Type declaration instruction Eg int sum; float ave; char name,code; Input/Output instruction Eg scanf(), printf() Arithmetic Instruction Control instruction

Data Types C Supports several different types of data, each of which may be represented differently within the computers memory. Basic data types are listed below: Data Type Description Typical Memory int integer quantity 2 bytes char single character 1 bytes float floating point number 4 bytes double double-precision 8 bytes floating point number

Escape Sequences in C Certain non printing characters can be expressed in terms of escape sequences Character Escape Sequence ASCII Value bell \a 007 backspace \b 008 horizontal tab \t 009 vertical tab \v 001 newline \n 010 quotation mark (“) \” 034 question mark(?) \? 063 backslash (\) \\ 092 null \0 000

First C Program /* library function for input and output */ #include main() { int a,b,sum; /*variable declaration*/ printf(“enter the first number::\n”); scanf(“%d”,&a); /*receiving data from user */ printf(“enter the second no: \n “); scanf(“%d”,&b); sum =a+b; /* calculating the sum*/ printf(“the sum of two numbers: %d\n“,sum); }

Preparing and Running a Complete C Program. Planning a program Design the algorithm for the given program Statements must be selected and sequenced in the most effective manner Writing a C program Translate the algorithm into equivalent C instructions Comments should be included within a C program A well written program should generate clear, legible output. The program should be user interactive

Entering, Compiling and Executing The program can be entered into the computer using an EDITOR. (In Unix vi editor is used) Eg. vi filename.c Compiling and executing the program cc filename.c The object code a.out is generated The program can be executed by entering a.out in the prompt Program asks for required input and generates the output

Assignment 01 Q1 : Which of the following are invalid variable names and why ? interestpaid si-int AVERAGE Percent. 123 dist in km ot pay Name FLOAT

Question 1.explain various data types available in C? Question2. Explain the keywords and Constants in C ? What restrictions apply to their use?

Programming Assignment 01 Q2 : Point out the errors, if any, in the following C statements: int = *150 ; name = ‘Ajay’; 3.14 * r*r = area; k=a*b+c(2.5a+b); m_inst =rate of interest * numberofyears /100; area = 3.14 * r **2;

Assignment 01 Q3 : A C program contains the following statements: #include int i,j,k; write appropriate scanf and printf functions to enter and print the numerical values for i,j and k Q4 : Each new c instruction has to be written on a separate line. (True/false)