Difference between revisions of "C and Cpp"

From Script | Spoken-Tutorial
Jump to: navigation, search
m (Nancyvarkey moved page CandC++ to C and Cpp without leaving a redirect)
 
(7 intermediate revisions by 4 users not shown)
Line 10: Line 10:
 
'''C++''' is a programming language developed by '''Bjarne Stroustrup''' starting in '''1979''' at '''Bell Labs'''. C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose, powerful programming language. C++ is an '''object oriented language'''. It supports features like  classes and objects, Polymorphism, Encapsulation, Inheritance etc. C++ is also used for hardware design.
 
'''C++''' is a programming language developed by '''Bjarne Stroustrup''' starting in '''1979''' at '''Bell Labs'''. C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose, powerful programming language. C++ is an '''object oriented language'''. It supports features like  classes and objects, Polymorphism, Encapsulation, Inheritance etc. C++ is also used for hardware design.
 
   
 
   
__TOC__
 
  
 +
The Spoken Tutorial effort for '''C''' and '''C++''' is led by Ashwini Patil from IIT BOMBAY, under the guidance of various Professors from IIT BOMBAY.
  
==Basic Level==                                                                         
+
Other Contributors : Chaitanya Mokashi, Ritwik Joshi, Dhawal Goyal
  
1) First C Program (Script) (Spoken-Tutorial)
+
'''Learners''': High School and UG/PG CSE/CS/IT students and anyone who wishes to learn basic programming.
  
 +
__TOC__
  
-Header Files
+
==Basic Level==                                                                         
  
<nowiki>--example: #include <stdio.h> </nowiki>
+
1) '''First C Program'''
  
-main()  
+
*-Header Files
 +
**<nowiki>example: #include <stdio.h> </nowiki>
 +
*main()  
 +
*Curly braces { }
 +
*printf()
 +
*semicolon ;
  
-Curly braces { }
+
*Compiling a C program
 +
**example: gcc filename.c -o output parameter
 +
*Executing a C program
 +
**example: ./output parameter
 +
*Errors
  
-printf()
 
  
-semicolon ;
+
2) '''First C++ Program'''
  
-Compiling a C program
+
*Header files
 +
**<nowiki>--example: #include <iostream> </nowiki>
 +
*main()
 +
*Curly braces { }
 +
*<nowiki>-cout<< </nowiki>
 +
*semicolon ;
  
--example: gcc filename.c -o output parameter  
+
*Compiling a C++ program
 +
**example: g++ filename.cpp -o output parameter
 +
*Executing a C program
 +
**example: ./output parameter  
  
-Executing a C program
 
  
--example: ./output parameter
+
3) '''Tokens in C and C++'''
  
-Errors  
+
*Data types, constants, identifiers
 +
*Keywords
 +
**example: if, break, else
 +
*Constants
 +
*Data types
 +
**example: int, float, char, double
 +
*Format specifiers
 +
**example: %d, %f, %c, %lf
 +
*Range of data types
 +
*Variables
 +
*Identifier
 +
*Errors  
  
  
2) First C++ Program (Script) (Spoken-Tutorial)
+
4) '''Functions in C and C++'''
  
 +
*What is a function
 +
*Syntax for declaration of a function
 +
*Function with arguments
 +
**example: return-type function-name(parameter);
 +
*Function without arguments
 +
**example: return-type function-name; 
 +
*Calling a function
 +
*Errors
  
-Header files
 
  
<nowiki>--example: #include <iostream> </nowiki>
+
5) '''Scope of Variables in C and C++'''
  
-main()
+
*Introduction
 +
*Syntax of declaring a variable
 +
**example: data-type var-name;
 +
*Syntax for initializing a variable
 +
**example: data-type var-name = value;
 +
*Scope of variables
 +
*Global variable
 +
*Local variable
 +
*Error
  
-Curly braces { }
 
  
<nowiki>-cout<< </nowiki>
+
6) '''If And Else If statement in C and C++'''
  
-semicolon ;
+
*What are Statements.
 +
*Syntax for if and
 +
*If-else Statement
 +
*Errors
  
-Compiling a C++ program
 
  
--example: g++ filename.cpp -o output parameter
+
7) '''Nested if and switch statement in C and C++'''
  
-Executing a C program
+
*Nested if statement.
 +
*Switch statement.
 +
*Syntax for nested-if statement
 +
*Syntax for switch statement
 +
*break statement
 +
*Comparison between nested if-else and switch statement
 +
*Errors
  
--example: ./output parameter
 
  
 +
8) '''Increment and Decrement Operators in C and C++'''
  
3) Tokens in C and C++  
+
*Increment Operator
 +
**example: ++  
 +
*Postfix increment
 +
**example: a++
 +
*Prefix increment
 +
**example: ++a
 +
*Decrement Operator
 +
**example: --
 +
*Postfix decrement
 +
**example: a--
 +
*Prefix decrement
 +
**example: --a
 +
*Typecasting
 +
*Errors
  
 
  
-Data types, constants, identifiers
+
9) '''Arithmetic Operators in C and C++'''
  
-Keywords
+
*Arithmetic Operators
 +
*Addition Operator
 +
**example: a + b
 +
*Subtraction Operator
 +
**example: a - b
 +
*Multiplication Operator
 +
**example: a * b
 +
*Division Operator
 +
**example: a \ b
 +
*Modulus Operator
 +
**example: a % b
 +
*Errors
  
--example: if, break, else
 
  
-Constants
+
10) '''Relational Operators in C and C++'''
  
-Data types
+
*Double Equal to
 +
**example: a == b
 +
*Not Equal to
 +
**example: a != b
 +
*Greater Than
 +
**example: a > b
 +
*Less Than
 +
**<nowiki>example: a < b </nowiki>
 +
*Greater than Equal To
 +
**<nowiki>example: a >= b </nowiki>
 +
*Less Than Equal To
 +
**<nowiki>example: a <= b </nowiki>
 +
*Errors
  
--example: int, float, char, double
 
  
-Format specifiers
+
11) '''Logical Operators in C and C++
 +
'''
 +
*And &&
 +
*Or ||
 +
*Not !
 +
*Errors
  
--example: %d, %f, %c, %lf
 
 
-Range of data types
 
 
-Variables
 
 
-Identifier
 
 
-Errors
 
 
 
4) Functions in C and C++
 
 
 
-What is a function
 
 
-Syntax for declaration of a function
 
 
-Function with arguments
 
 
--example: return-type function-name(parameter);
 
 
-Function without arguments
 
 
--example: return-type function-name; 
 
 
-Calling a function
 
 
-Errors
 
 
 
5) Scope of Variables in C and C++
 
 
 
-Introduction
 
 
-Syntax of declaring a variable
 
 
--example: data-type var-name;
 
 
-Syntax for initializing a variable
 
 
--example: data-type var-name = value;
 
 
-Scope of variables
 
 
-Global variable
 
 
-Local variable
 
 
-Error
 
 
 
6) Check the conditions in a program in C and C++
 
 
 
-What are Statements.
 
 
-Syntax for if and
 
 
-If-else Statement
 
 
-Errors
 
 
 
7) Nested if and switch statement in C and C++
 
 
 
-Nested if statement.
 
 
-Switch statement.
 
 
-Syntax for nested-if statement
 
 
-Syntax for switch statement
 
 
-break statement
 
 
-Comparison between nested if-else and switch statement
 
 
-Errors
 
 
 
8) Increment and Decrement Operators in C and C++
 
 
 
-Increment Operator
 
 
--example: ++
 
 
-Postfix increment
 
 
--example: a++
 
 
-Prefix increment
 
 
--example: ++a
 
 
-Decrement Operator
 
 
--example: --
 
 
-Postfix decrement
 
 
--example: a--
 
 
-Prefix decrement
 
 
--example: --a
 
 
-Typecasting
 
 
-Errors
 
 
 
9) Arithmetic Operators in C and C++
 
 
 
-Arithmetic Operators
 
 
-Addition Operator
 
 
--example: a + b
 
 
-Subtraction Operator
 
 
--example: a - b
 
 
-Multiplication Operator
 
 
--example: a * b
 
 
-Division Operator
 
 
--example: a \ b
 
 
-Modulus Operator
 
 
--example: a % b
 
 
-Errors
 
 
 
10) Relational Operators in C and C++
 
 
 
-Double Equal to
 
 
--example: a == b
 
 
-Not Equal to
 
 
--example: a != b
 
 
-Greater Than
 
 
--example: a > b
 
 
-Less Than
 
 
<nowiki>--example: a < b </nowiki>
 
 
-Greater than Equal To
 
 
--example: a >= b
 
 
-Less Than Equal To
 
 
<nowiki>--example: a <= b </nowiki>
 
 
-Errors
 
 
 
11) Logical Operators in C and C++
 
 
 
-And &&
 
 
-Or ||
 
 
-Not !
 
 
-Errors
 
 
 
12) Loops in C and C++
 
 
 
-Loops
 
 
-Syntax for while and do-while loop
 
 
-Comparison of while and do-while loop
 
 
-Syntax for
 
 
-for loop
 
 
-Errors
 
  
 
==Intermediate level==   
 
==Intermediate level==   
  
13) Arrays in C and C++  
+
12) '''Loops in C and C++'''
  
 +
*Loops
 +
*Syntax for while and do-while loop
 +
*Comparison of while and do-while loop
 +
*Syntax for
 +
*for loop
 +
*Errors
  
-What are arrays
 
  
-1-D Arrays  
+
13) '''Arrays in C and C++'''
  
-Syntax for Declaration of arrays  
+
*What are arrays
 +
*1-D Arrays
 +
*Syntax for Declaration of arrays  
 +
**<nowiki>example: data type array_name [size]; </nowiki>
 +
*Syntax for Initialization of arrays
 +
**<nowiki>example: data type array_name [size]=value; </nowiki>
 +
*Accepting values from the user
 +
*Errors
  
<nowiki>--example: data type array_name [size]; </nowiki>
 
 
-Syntax for Initialization of arrays
 
 
<nowiki>--example: data type array_name [size]=value; </nowiki>
 
 
-Accepting values from the user
 
 
-Errors
 
 
 
14) Working with 2-D Arrays in C and C++
 
 
 
-What are 2-D Arrays.
 
 
-Range of arrays
 
 
-Syntax for Declaration of 2-D arrays
 
 
<nowiki>--example: data type array_name[row][column]; </nowiki>
 
 
-Syntax for initialization of 2-D arrays
 
 
<nowiki>--example: data type array_name[row][column]= </nowiki>
 
  
 +
14) '''Working with 2-D Arrays in C and C++'''
 +
*What are 2-D Arrays.
 +
*Range of arrays
 +
*Syntax for Declaration of 2-D arrays
 +
**example: data type array_name[row][column];
 +
*Syntax for initialization of 2-D arrays
 +
**example: data type array_name[row][column]=
 
{  
 
{  
 
+
 
 
{row-val},{col-val}  
 
{row-val},{col-val}  
 
+
 
 
};  
 
};  
 +
*Errors
  
-Errors
 
  
 +
15) '''Strings in C and C++'''
  
15) Strings in C and C++
+
*What is a string
 +
*Syntax for declaring a string
 +
*Syntax for initializing a string
 +
*To read a string from keyboard
 +
*Errors
  
  
-What is a string
+
16) '''String Library Functions in C and C++'''
  
-Syntax for declaring a string  
+
*What are string library functions.
 +
*Types of string library functions
 +
**Strcpy
 +
**Strlen
 +
**Strcmp
 +
**Strcat
 +
*Errors
  
-Syntax for initializing a string
+
==Advanced level== 
  
-To read a string from keyboard
+
17) '''Working with Structures in C and C++'''
  
-Errors
+
*Introduction
 +
*Syntax of structures
 +
*Declaration and initialization
 +
*Declaration of structure variable
 +
*Accessing structure variables
  
  
16) String Library Functions in C and C++
+
18) '''Understanding Pointers in C and C++'''
 
+
 
+
-What are string library functions.
+
 
+
-Types of string library functions
+
 
+
-Strcpy
+
 
+
-Strlen
+
 
+
-Strcmp
+
 
+
-Strcat
+
 
+
-Errors
+
 
+
 
+
17) Working with Structures in C and C++
+
 
+
 
+
-Introduction
+
 
+
-Syntax of structures
+
 
+
-Declaration and initialization
+
 
+
-Declaration of structure variable
+
 
+
-Accessing structure variables
+
 
+
 
+
18) Understanding Pointers in C and C++  
+
 
+
 
+
-Introduction
+
 
+
-Syntax of Pointer
+
 
+
--example: int *iptr;
+
 
+
-Declaration
+
 
+
--example: int a;
+
  
 +
*Introduction
 +
*Syntax of Pointer
 +
**example: int *iptr;
 +
*Declaration
 +
**example:
 +
int a;
 
(integer a)  
 
(integer a)  
 
 
int *aptr;  
 
int *aptr;  
 
 
(pointer to an integer *aptr)  
 
(pointer to an integer *aptr)  
 
 
aptr = &a;  
 
aptr = &a;  
 
 
(aptr set to address of a)  
 
(aptr set to address of a)  
 
 
Address Pointer  
 
Address Pointer  
 +
*Errors
  
-Errors
 
 
 
19) Function pass by value and pass by reference
 
 
 
-types of function calls
 
 
-function pass by value
 
 
-function pass by reference
 
 
 
20) Files in C
 
  
 +
19) '''Function call in C and C++'''
  
-File handling functions
+
*types of function calls
 +
*function pass by value
 +
*function pass by reference
  
-Opening a File closing a file
 
  
--example: fopen, fclose
+
20) '''File Handling in C'''
  
-Reading data from a File
+
*File handling functions
 +
*Opening a File closing a file
 +
**example: fopen, fclose
 +
*Reading data from a File

Latest revision as of 15:34, 6 February 2020

Introduction to C

Powerful features, simple syntax, and portability make C a preferred language among programmers for business and industrial applications.Portability means that C programs written for a computer with a particular kind of processor, say Intel, can be executed on computers with different processors such as Motorola, Sun Sparc, or IBM with little or no modification.C language is widely used in the development of operating systems.

An Operating System(OS) is a software(collection of programs) that controls the various functions of a computer. Also it makes other programs on your computer work.

For example, you cannot work with a word processor program, such as Microsoft Word, if there is no operating system installed on your computer.Windows, Unix, Linux, Solaris, and MacOS are some of the popular operating systems.

Dennis M. Ritchie, a systems engineer at Bell Laboratories, New Jersey developed C in the early 1970’salthough designed for the Unix operating system, it soon proved itself a powerful, general purpose programming language.

C++ is a programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose, powerful programming language. C++ is an object oriented language. It supports features like classes and objects, Polymorphism, Encapsulation, Inheritance etc. C++ is also used for hardware design.


The Spoken Tutorial effort for C and C++ is led by Ashwini Patil from IIT BOMBAY, under the guidance of various Professors from IIT BOMBAY.

Other Contributors : Chaitanya Mokashi, Ritwik Joshi, Dhawal Goyal

Learners: High School and UG/PG CSE/CS/IT students and anyone who wishes to learn basic programming.

Basic Level

1) First C Program

  • -Header Files
    • example: #include <stdio.h>
  • main()
  • Curly braces { }
  • printf()
  • semicolon ;
  • Compiling a C program
    • example: gcc filename.c -o output parameter
  • Executing a C program
    • example: ./output parameter
  • Errors


2) First C++ Program

  • Header files
    • --example: #include <iostream>
  • main()
  • Curly braces { }
  • -cout<<
  • semicolon ;
  • Compiling a C++ program
    • example: g++ filename.cpp -o output parameter
  • Executing a C program
    • example: ./output parameter


3) Tokens in C and C++

  • Data types, constants, identifiers
  • Keywords
    • example: if, break, else
  • Constants
  • Data types
    • example: int, float, char, double
  • Format specifiers
    • example: %d, %f, %c, %lf
  • Range of data types
  • Variables
  • Identifier
  • Errors


4) Functions in C and C++

  • What is a function
  • Syntax for declaration of a function
  • Function with arguments
    • example: return-type function-name(parameter);
  • Function without arguments
    • example: return-type function-name;
  • Calling a function
  • Errors


5) Scope of Variables in C and C++

  • Introduction
  • Syntax of declaring a variable
    • example: data-type var-name;
  • Syntax for initializing a variable
    • example: data-type var-name = value;
  • Scope of variables
  • Global variable
  • Local variable
  • Error


6) If And Else If statement in C and C++

  • What are Statements.
  • Syntax for if and
  • If-else Statement
  • Errors


7) Nested if and switch statement in C and C++

  • Nested if statement.
  • Switch statement.
  • Syntax for nested-if statement
  • Syntax for switch statement
  • break statement
  • Comparison between nested if-else and switch statement
  • Errors


8) Increment and Decrement Operators in C and C++

  • Increment Operator
    • example: ++
  • Postfix increment
    • example: a++
  • Prefix increment
    • example: ++a
  • Decrement Operator
    • example: --
  • Postfix decrement
    • example: a--
  • Prefix decrement
    • example: --a
  • Typecasting
  • Errors


9) Arithmetic Operators in C and C++

  • Arithmetic Operators
  • Addition Operator
    • example: a + b
  • Subtraction Operator
    • example: a - b
  • Multiplication Operator
    • example: a * b
  • Division Operator
    • example: a \ b
  • Modulus Operator
    • example: a % b
  • Errors


10) Relational Operators in C and C++

  • Double Equal to
    • example: a == b
  • Not Equal to
    • example: a != b
  • Greater Than
    • example: a > b
  • Less Than
    • example: a < b
  • Greater than Equal To
    • example: a >= b
  • Less Than Equal To
    • example: a <= b
  • Errors


11) Logical Operators in C and C++

  • And &&
  • Or ||
  • Not !
  • Errors


Intermediate level

12) Loops in C and C++

  • Loops
  • Syntax for while and do-while loop
  • Comparison of while and do-while loop
  • Syntax for
  • for loop
  • Errors


13) Arrays in C and C++

  • What are arrays
  • 1-D Arrays
  • Syntax for Declaration of arrays
    • example: data type array_name [size];
  • Syntax for Initialization of arrays
    • example: data type array_name [size]=value;
  • Accepting values from the user
  • Errors


14) Working with 2-D Arrays in C and C++

  • What are 2-D Arrays.
  • Range of arrays
  • Syntax for Declaration of 2-D arrays
    • example: data type array_name[row][column];
  • Syntax for initialization of 2-D arrays
    • example: data type array_name[row][column]=

{

{row-val},{col-val}

};

  • Errors


15) Strings in C and C++

  • What is a string
  • Syntax for declaring a string
  • Syntax for initializing a string
  • To read a string from keyboard
  • Errors


16) String Library Functions in C and C++

  • What are string library functions.
  • Types of string library functions
    • Strcpy
    • Strlen
    • Strcmp
    • Strcat
  • Errors

Advanced level

17) Working with Structures in C and C++

  • Introduction
  • Syntax of structures
  • Declaration and initialization
  • Declaration of structure variable
  • Accessing structure variables


18) Understanding Pointers in C and C++

  • Introduction
  • Syntax of Pointer
    • example: int *iptr;
  • Declaration
    • example:

int a; (integer a) int *aptr; (pointer to an integer *aptr) aptr = &a; (aptr set to address of a) Address Pointer

  • Errors


19) Function call in C and C++

  • types of function calls
  • function pass by value
  • function pass by reference


20) File Handling in C

  • File handling functions
  • Opening a File closing a file
    • example: fopen, fclose
  • Reading data from a File