Data Types and Input Output in C. Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d.

Slides:



Advertisements
Similar presentations
Single Variable and a Lot of Variables The declaration int k; float f; reserve one single integer variable called k and one single floating point variable.
Advertisements

C Intro.
41 A Depth Program #include int main(void) { int inches, feet, fathoms; //declarations fathoms = 7; feet = 6 * fathoms; inches = 12 * feet; printf(“Wreck.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
Introduction to C Programming CE Lecture 2 Basics of C programming.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
1 CSE1301 Computer Programming: Lecture 9 Input/Output.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
CS 161 Introduction to Programming and Problem Solving Chapter 13 Console IO Herbert G. Mayer, PSU Status 9/8/2014 Initial content copied verbatim from.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
First Program in C With Output. C Language Keywords.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
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.
A First Book of ANSI C Fourth Edition Chapter 3 Processing and Interactive Input.
Data Types. Data types Data type tells the type of data, that you are going to store in memory. It gives the information to compiler that how much memory.
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
1 C Programming Week 2 Variables, flow control and the Debugger.
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
3. FORMATTED INPUT/OUTPUT. The printf Function The first argument in a call of printf is a string, which may contain both ordinary characters and conversion.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
Khalid Rasheed Shaikh Computer Programming Theory 1.
 Integers and Characters  Character Strings  Input and Output.
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
CSE1301 Computer Programming: Lecture 6 Input/Output.
S CCS 200: I NTERACTIVE I NPUT Lect. Napat Amphaiphan.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
Sudeshna Sarkar, IIT Kharagpur 1 I/O in C + Misc Lecture –
CSCI 130 Basic Input and Output Chapter 9. The printf ( ) function Printf(“\nThe value of x is %d”, x); Displayed to screen (assume x = 12): –The value.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
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.
Introduction to Programming Lecture 5: Interaction.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
7. BASIC TYPES. Systems of numeration Numeric Types C’s basic types include integer types and floating types. Integer types can be either signed or unsigned.
BIL 104E Introduction to Scientific and Engineering Computing Lecture 2.
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.
Formatted I/O ä ä Standard Output ä ä printf() family of functions ä ä Standard Input ä ä scanf() family of functions.
Arithmetic Instructions. Integer and Float Conversions.
Introduction to Computing Lecture 03: Basic input / output operations Introduction to Computing Lecture 03: Basic input / output operations Assist.Prof.Dr.
Dr. Sajib Datta Sep 8,  char type technically is an integer type  Computer uses numeric codes to represent characters, and store characters.
Lecture2.
Zhang Hongyi CSCI2100B Data Structures Tutorial 3
Formatted Input/Output
Input/output.
7. BASIC TYPES.
Chapter 2 Overview of C.
Getting Started with C.
I/O in C + Misc Lecture Sudeshna Sarkar, IIT Kharagpur.
Formatted Input/Output
Input and Output Lecture 4.
Input/Output Input/Output operations are performed using input/output functions Common input/output functions are provided as part of C’s standard input/output.
CSI 121 Structured Programming Language Lecture 7: Input/Output
توابع ورودي-خروجي.
אבני היסוד של תוכנית ב- C
מ- C++ ל- C קרן כליף.
A First Book of ANSI C Fourth Edition
Chapter 4 Managing Input and Output Operations
DATA TYPES There are four basic data types associated with variables:
Presentation transcript:

Data Types and Input Output in C

Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d bytes", sizeof(ch)); return 0; }

Size of a Character in C #include int main() { char ch; ch = 'A'; printf("ch = %c\n",ch); printf("size of char = %d bytes", sizeof(ch)); getch(); return 0; }

Using ASCII Values #include int main() { char ch; ch = 65; printf("ch = %c\n",ch); printf("size of char = %d bytes", sizeof(ch)); return 0; }

Short int #include int main() { short sh; sh = 6; printf("sh = %d\n",sh); printf("size of short = %d bytes", sizeof(sh)); return 0; }

int #include int main() { int i; i = 6000; printf("i = %d\n",i); printf("size of int = %d bytes", sizeof(i)); return 0; }

long #include int main() { long l; l = ; printf("l = %ld\n",l); printf("size of long = %d bytes", sizeof(l)); return 0; }

Float #include int main() { float flt; flt = ; printf("flt = %f\n",flt); printf("size of float = %d bytes", sizeof(flt)); return 0; }

double #include int main() { double dbl; dbl = ; printf("dbl = %f\n",dbl); printf("size of double = %d bytes", sizeof(dbl)); return 0; }

Long double #include int main() { long double ldbl; ldbl = ; printf("ldbl = %Lf\n",ldbl); printf("size of long double = %d bytes", sizeof(ldbl)); return 0; }

i

Input/Output Operations and Functions

printf function

Printing expressions of variables

scanf function

,

A First Book of ANSI C, Fourth Edition23 Interactive Input (continued) This statement produces a prompt Address operator (&)

A First Book of ANSI C, Fourth Edition24 Interactive Input (continued) scanf() can be used to enter many values scanf(“%f %f",&num1,&num2); //"%f%f" is the same A space can affect what the value being entered is when scanf() is expecting a character data type – scanf(“%c%c%c",&ch1,&ch2,&ch3); stores the next three characters typed in the variables ch1, ch2, and ch3 ; if you type x y z, then x is stored in ch1, a blank is stored in ch2, and y is stored in ch3 – scanf (“%c %c %c",&ch1,&ch2,&ch3); causes scanf() to look for three characters, each character separated by one space

A First Book of ANSI C, Fourth Edition25 Interactive Input (continued) In printing a double-precision number using printf(), the conversion control sequence for a single-precision variable, %f, can be used When using scanf(), if a double-precision number is to be entered, you must use the %lf conversion control sequence scanf() does not test the data type of the values being entered In scanf(“%d %f", &num1, &num2), if user enters 22.87, 22 is stored in num1 and.87 in num2

scanf #include int main() { char ch, ch1, ch2; scanf("%c%c%c", &ch, &ch1, &ch2); printf("ch = %c\n", ch); printf("ch1 = %c\n", ch1); printf("ch2 = %c\n", ch2); return 0; }

scanf #include int main() { char ch, ch1, ch2; scanf("%c %c %c", &ch, &ch1, &ch2); printf("ch = %c\n", ch); printf("ch1 = %c\n", ch1); printf("ch2 = %c\n", ch2); return 0; }