C and C++

by JustEtc Publications Ltd




Distributed by justEtc

Introduction to C (Structured Programming)



Just went through the book "The C Programming Language" by Kernighan and Ritchie. I read the book several times in the past. Just reviewed it again.



Introduction to the C Programming Language



Introduction to CProgramming Languageby Mr. S. Ahmed

Topics/Concepts

Structure of a C Program

How does a C program look like?

#include 

main()
{

	printf("hello, world\n");

}

The ‘Hello World’ Program

Program Execution, Program in Action

Remember

Some Variations of the Printf() Function

Concepts to Understand

Concepts to Understand
Note:

Variable and Expressions

Control Flow. What is it?

Control Flow

if (expression)
	statement1
else
	statement2
----
if (expression)
	statement1
else if (expression)
	statement2
else
	statement3

If then Else

if (a > b)
		z = a;
	else
		z = b;
----
	if (a > b)
		z = a;
	else if (b>a)
		z = b;
   else if (a==b)
		x=y;
  else
	     printf(“nothing”);

Switch-Case

Switch-Case Equivalent of If

Switch

switch (expression) {
	case const-expr: statements
	case const-expr: statements
	default: statements
}

Loop

Loops Syntax

while (expression){
	Statement
}

for (expr1; expr2; expr3){
	Statement
}

expr1;
while (expr2) {
	statement
	expr3;
}


Loops Example

Loop Example

  • Break and Continue

    Go to Statement

    Syntax
    Go to Label
    ……
    ………
    Label:
    …….
    
    

    Pointers

    Pointers

    Pointers

    Pointers