TaleemBay
Study
UniversitiesScholarshipsFeesDates
TaleemBay

Empowering students with Next-Gen tools for a brighter future. Your one-stop destination for education in Pakistan.

Quick Links

  • Universities
  • Study Center
  • Past Papers
  • Date Sheets
  • Results

Support

  • About Us
  • Contact
  • Privacy Policy
  • Terms of Service
  • Advertise

Contact Us

  • Arfa Software Technology Park,
    Ferozepur Road, Lahore
  • +92 300 1234567
  • hello@taleembay.com

© 2026 TaleemBay. All rights reserved.

Designed with ❤️ for Pakistan

Home
Unis
Study

Study Center

Overview
9th Class10th Class11th Class12th Class

Resources

Past PapersDate Sheets

Need Notes?

AI-powered search for instant answers.

Chapter 10
computer-science • intermediate 12th

Chapter 10: Input and Output

Comprehensive notes for Chapter 10 Input and Output. Covers printf, scanf, Format Specifiers, Escape Sequences, and Character I/O.

Input and Output Basics

Input: Process of giving something to the computer. Standard Input: Input via keyboard.

Output: Process of getting something from the computer. Standard Output: Output displayed on monitor.

Header File: stdio.h (Standard Input Output) contains definitions for standard I/O functions like printf and scanf.

printf Function

Definition: Used to display output on monitor. Can display text, constants, or variable values.

Syntax: printf("Control String", Argument List);

  • Control String: Text, Format Specifiers (starts with %), Escape Sequences (starts with \).
  • Argument List: Variables or values to be printed, matching the format specifiers.

Format Specifiers

Starts with % symbol. Determines data type, field width, and format.

  • Integer: %d (decimal), %i (integer), %o (octal), %x (hex lower), %X (hex upper), %u (unsigned).
  • Float: %f (float/double), %e (scientific lower), %E (scientific upper), %g (shortest of %f or %e).
  • Character/String: %c (char), %s (string).

Field Width: Number of columns used to display value to text (e.g., %5d uses 5 columns).

Precision: Number of decimal places for floats (e.g., %.2f displays 2 decimal places).

scanf Function

Definition: Used to take input from the user. Stores input in specified variables.

Syntax: scanf("Format String", &variable1, &variable2, ...);

  • Format String: Contains format specifiers matching the data types of variables.
  • Address Operator (&): Must be used with variable names (except strings) to specify memory address.

Escape Sequences

Special characters starting with backslash (\) used to modify output format. Not printed themselves.

  • \n: New Line. Moves cursor to start of next line.
  • \t: Horizontal Tab. Moves cursor to next tab stop.
  • \b: Backspace. Moves cursor one position back.
  • \r: Carriage Return. Moves cursor to beginning of current line.
  • \f: Form Feed (Page Break).
  • \': Print Single Quote.
  • \": Print Double Quote.
  • \\: Print Backslash.

Character I/O (getch vs getche)

Functions from conio.h to input single characters.

  • getch(): Get Character. Input not echoed (displayed) on screen. Often used to pause program output.
  • getche(): Get Character Echo. Input is displayed on screen as typed.

String I/O (gets vs puts)

  • gets(): Get String. Reads a line of text (including spaces) until Enter is pressed. Replaces scanf limitation with spaces.
  • puts(): Put String. Displays a string on screen and automatically adds a new line at the end.

Other Functions

  • clrscr(): Clear Screen. Clears text from standard output. Defined in conio.h.
  • sizeof(): Operator to find the size of data type or variable in bytes. (e.g., sizeof(int) returns 2).
Download PDFPDF