Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

C Programming: I/O Functions and Data Types, Slides of Information Technology

An overview of input and output functions and data types in c programming. It covers formatted and unformatted i/o functions, such as scanf() and printf(), and their syntax. It also explains the concept of constants, data types, and their sizes and ranges. Useful for students and lifelong learners who want to understand the basics of c programming.

Typology: Slides

2012/2013

Uploaded on 12/31/2013

mandhata
mandhata 🇮🇳

4.5

(13)

68 documents

1 / 51

Toggle sidebar

Related documents


Partial preview of the text

Download C Programming: I/O Functions and Data Types and more Slides Information Technology in PDF only on Docsity! PROGRAM STRUCTURE docsity.com Input /Output Statements Reading ,processing and writing of data are the three essential functions of a computer program.Most programs take some data as input and display the processed data, often known as information or results on a suitable medium.So far we have used one method of providing value to the program users. In this method value assigned to variables through the assignment statements such as X=5 and Y=11. docsity.com Formatted output function is printf( ) Output data can be written from the computer onto a standard output device using the library function printf. Syntax: printf(“control,string”,arg1,arg2,...argn); Formatted Output function docsity.com Formatted Output function Control string consists of three types of items:-  Characters that will be printed on the screen as they appear.  Format specification that define the output format for display of each item.  Escape sequence characters such as \n (new line)and\t(tab) . Arg1, arg2,…….argn are the variables whose values are formatted and printed acording to the specification of control string. docsity.com Unformatted functions  There are several library functions under this categories: those that can deal with a single character and those that can deal with a string of characters. Single Character Input functions: getchar( ), getche( ), getch( ). Single Character Output:- putch( ) and putchar( ). docsity.com Unformatted Output functions putchar( ) like getchar, there is an analogous function putchar for writing or printing one character at a time on the screen.  Syntax: putchar(variable_name); Where variable_name is a char type variable containing a character. This statement displays the character contained in the variable, name on the screen. docsity.com Unformatted Output functions Example:- answer =‘Y’; putchar (answer); will display the character Y on the screen. The statement putchar(‘\n’); would cause the cursor on the screen to move to the beginning of the next line. docsity.com Constants These are the tokens whose value do not change during the program execution. The following rules apply to all numeric type constants:- -Commas and blank spaces cannot be included within the constants. -The constant can be preceded by a minus(-) sign if desired. -The value of a constants cannot exceed minimum and maximum bounds. docsity.com Variable names- Rules  Should not be a reserved word like int etc..  Should start with a letter or an underscore(_)  Can contain letters, numbers or underscore.  No other special characters are allowed including space  Variable names are case sensitive A and a are different. docsity.com Data types in C  Primary(fundamental) data types  int, float, double, char  Derived data types  Arrays  Pointers  functions  User defined data types  Structures, union and enumerated docsity.com Fundamental data types Fundamental data types are the built in data types and can be classified as follows:-  Integer type: an integer is an integral whole number without a decimal point. They are of nine type: short int, unsigned short int, signed int, unsigned int, signed int, long int, unsigned long int, signed long int. docsity.com Derived Data Types Array – An array is collection of identical data objects which are stored in consecutive memory locations under a common heading or variable name. docsity.com Arrays  Arrays fall under aggregate data type  Aggregate – More than 1  Arrays are collection of data that belong to same data type  Arrays are collection of homogeneous data  Array elements can be accessed by its position in the array called as index docsity.com Arrays  Array index starts with zero  The last index in an array is num – 1 where num is the no of elements in a array  int a[5] is an array that stores 5 integers  a[0] is the first element where as a[4] is the fifth element  We can also have arrays with more than one dimension  float a[5][5] is a two dimensional array. It can store 5x5 = 25 floating point numbers  The bounds are a[0][0] to a[4][4] docsity.com Pointers  Pointer is a special variable that stores address of another variable  Addresses are integers. Hence pointer stores integer data  Size of pointer = size of int  Pointer that stores address of integer variable is called as integer pointer and is declared as int *ip; docsity.com User defined Data Types Structure A collection of related variables of the same and/or different data types. The structure is called a record and the variables in the record are called members or fields. docsity.com Uses of structure struct student { Char name; int rollno; float marks; }; // End struct Struct student s1; docsity.com ARITHMETIC OPERATORS Arithmetic operators are the simplest and basic operators that do arithmetic operations. These operators require two variables and are called binary operators. The various arithmetic operators in C are: OPERATOR MEANING ASSOCIATIVITY + - * / % ADDITION SUBTRACTION MULTIPICATION DIVISION MODULUS (remainder of integer division) L R L  R L  R L  R L  R docsity.com Use of arithmetic operators let a=5, b=7 and a, b are integers a + b = 5+7 = 12 a – b = 5-7 = -2 There is no exponentiation operator in C. however there is library function (pow) to carry out exponentiation. docsity.com Arithmetic operators When operands are of different data type , then type conversion take place and data type of the value returned by an expression is of highest priority  Operation between int and float will result in float.  Operation between float and double will result in double.  Operation between int and char will result in int.  Operation between float and char will result in float.  Operation between int and double will result in double. docsity.com Logical Operators Operator Meaning && Logical AND || Logical OR ! Logical NOT Logical expression or a compound relational expression- An expression that combines two or more relational expressions Ex:- if (a==b && b==c) docsity.com Truth Table a b Value of the expression a && b a || b 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 docsity.com Increment & Decrement Operators C supports 2 useful operators namely Increment ++ The ++ operator adds a value 1 to the operand ++a or a++ Decrement –- The –- operator subtracts 1 from the operand --a or a-- docsity.com Bitwise operators These operators allow manipulation of data at the bit level Operator Meaning & Bitwise AND | Bitwise OR ^ Bitwise exclusive OR << Shift left >> Shift right docsity.com Special operators  Comma operator ( ,)  sizeof operator – sizeof( )  Pointer operators – ( & and *)  Member selection operators – ( . and ->) docsity.com Expressions An expressions represents a single data item, such as a a number or a character. The expression may consist of a single entity, such as a constant, a variable, an array element or a reference to a function. Expressions can also represent logical condition that are either true or false. e.g. c=a+b x= =y i= i+1 docsity.com Tokens A token is a collection of characters whose significance is its collectivity rather than individuality.  Identifiers  Keywords  Literals or Constants  Operators  Punctuators or Special Symbols  Strings docsity.com Keywords  auto  break  Case  Char  Continue  Default  Delete  Do  Double  Else  Float  For  Friend  Goto  If  Int  Long  Private docsity.com Writing the first program  #include<stdio.h>  int main()  {  printf(“Hello”);  return 0;  }  This program prints Hello on the screen when we execute it docsity.com Input and Output  Input  scanf(“%d”,&a);  Gets an integer value from the user and stores it under the name “a”  Output  printf(“%d”,a)  Prints the value present in variable a on the screen docsity.com THANKS docsity.com
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved