0% found this document useful (0 votes)
7 views7 pages

C Syllabus 2

The document provides a comprehensive overview of C programming, covering installation of IDEs and compilers, syntax, data types, operators, and control structures. It includes details on variable declaration, functions, arrays, pointers, strings, structures, unions, and dynamic memory allocation. Additionally, it offers exercises and examples to illustrate various programming concepts and techniques.

Uploaded by

sharmaneeti0204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

C Syllabus 2

The document provides a comprehensive overview of C programming, covering installation of IDEs and compilers, syntax, data types, operators, and control structures. It includes details on variable declaration, functions, arrays, pointers, strings, structures, unions, and dynamic memory allocation. Additionally, it offers exercises and examples to illustrate various programming concepts and techniques.

Uploaded by

sharmaneeti0204
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

C Programming

● Installation
■ IDE (Integrated Development Environment) --> VS Code
■ Compiler --> Mingw - gcc
■ Extensions --> C C++, Code runner

● Syntax

● Basic Flow - BTS - gcc -Wall -save-temps main.c


■ Preprocessing --> .i (remove comments, include files)
■ Compilation --> .s (convert .I file into assembly level instructions)
■ Assembly --> .o (convert .s file into machine level instructions)
■ Linking --> .exe (executable file)
■ Loading --> Program load in RAM

● C Program --> Keywords + Identifiers + Literal / Constant + String + Symbols

● Variable Declaration
■ A name given to a memory location
■ Declared by writing type variable_name;
■ Initialized and declared by type variable_name = value;

● Valid / Invalid Variable name


■ Can contain alphabets, digits, and underscore ( _ )
■ A variable name can start with an alphabet and underscore only.
■ Can't start with a digit.
■ No white space & reserved keywords are allowed.
■ Valid variable names: int deepak, float deepak123, char _deepak34
■ Invalid variable names: $deepak, int 77 deepak, char long;

● Valid / Invalid declaration


● Data Types
■ Basic Data Types
◆ Int ( 4 byte ) --> 1, 2, 3 etc
◆ Float ( 4 byte ) --> 1.2, 2.2 etc
◆ Double ( 8 byte ) --> same as float
◆ Char ( 1 byte ) --> a, b, c etc
■ Derived Data Types
◆ Array

◆ Pointer

◆ Structure

◆ Union

■ Enumeration Data Types


◆ Enum

■ Void Data Type


◆ void (null)

● Operators
■ Arithmetic Operators
◆ +, -, *, /, % --> modulus
■ Relational / Conditional / Comparison Operators
◆ ==, >=, <=, <, >, !=
■ Logical Operators
◆ && --> AND, || --> OR, ! --> NOT
■ Assignment Operators
◆ =, +=, -=, *=, /=

● Keyword or Functions
■ Printf(); --> use to print the character / result / output
■ Scanf(); --> use to read character / value assign
■ Sizeof(); --> use to check size of data types

● Format Specifier of Data Types


■ Int --> %d Ex: scanf(‘’%d’’, &a);
■ Char --> %c
■ String --> %s
■ Float --> %f
■ Long --> %l
■ Double --> %lf
■ Long double --> %LF

● Constant --> const, #define

● Escape Sequences --> \a, \b, \n, \t, \v, \\, \’, \”

● Comments in C --> //---------, /* --------- */

● A program of Hello World!

● A program to Add two numbers

● Arithmetic Operation b/w -->


■ Int + int = int
■ Int + float = float
■ Float + float = float

● Operator Precedence in C
■ 1st --> !
■ 2nd --> *, /, %
■ 3rd --> +, -
■ 4th --> <, >, <=, >=
■ 5th --> ==, !=
■ 6th --> &&
■ 7th --> ||
■ 8th --> =

● Ex-1 : Print multiplication table of a number entered by the user - 2 X 1 = 2

● If Else
■ If
■ Else
■ Else if
■ Nested If
■ Exercise:
◆ C program to convert temperature from Fahrenheit to Celsius and Celsius to
Fahrenheit (F = (C x 1.8)+ 32) (C = (F - 32) x 0.556)
◆ C program to check whether a character is an alphabet or not

◆ C program to check vowels or consonants.

◆ C program to check whether the triangle is valid or not if angles are given

◆ C program to enter student marks and find percentage and grade


A college has the following rules for the grading system:
1. Below 25% – F
2. 25% to 45% – E
3. 46% to 50% – D
4. 51% to 60% – C
5. 61% to 80% – B
6. Above 80% – A
Ask the user to enter the mark of 5 subjects and print the corresponding grade.

● Ternary Operator

● Switch Case
■ Rules:
◆ Switch expression must be int or char.

◆ Case value must be an integer or character.

◆ Break is not a must.

■ Exercise:
◆ Write a C program to print day of week name using switch case.
◆ Write a C program print total number of days in a month using switch case.
◆ Write a C program to check whether an alphabet is vowel or consonant using switch
case.
◆ Write a C program to find the maximum between two numbers using a switch case.
◆ Write a C program to check whether a number is even or odd using a switch case.
◆ Write a C program to check whether a number is positive, negative or zero using a
switch case.
◆ Write a C program to create Simple Calculator using a switch case.

● Loops
■ Types:
◆ While Loop

◆ Do While Loop

◆ For Loops

■ Advantages:
◆ Code reuse-ability.

◆ Saves time

◆ Traversing Arrays

● Break;

● Continue;

● Functions
■ Used to divide a large c program into smaller pieces.
■ A function can be called multiple times to provide reusability to the C program.
■ Also called procedure or subroutine

● Recursion / Recursive Function


■ Recursive functions or Recursion is a process when a function calls a copy of itself to work
on a smaller problem.
■ Any function which calls itself is called a recursive function.
■ A termination condition (base case) is set to prevent infinite self-copies.
● Arrays --> An array is a collection of similar elements

● Pointers --> Data type which holds the address of other data types

● Strings
■ C language does not support strings as a data type.
■ We express strings using an array of characters terminated by a null character ('\0').
■ String: array of characters terminated by NULL character / null terminated character array
■ Gets(); --> to take string from user
■ Puts(); --> to print string as output
■ We can create a character array using the following ways:
◆ Char name[] = "deepak";

◆ Char name[] = {‘d’,’e’,’e’,’p’,’a’,’k’,’\0’};

● String Functions --> C Library: <string.h>


■ Strlen(str) --> used for count the string length
■ Strrev(str) --> used to show reverse of a string
■ Strcpy(target, source) --> used for copy the code from source to target
■ Strcat(str1, str2) --> concatenate two strings
■ Strcmp(str1, str2) --> used to compare two strings

● Structures --> Structure is a collection of non-similar elements

● Typedef

● Unions --> Union is a collection of similar / non-similar elements but we can use only one at a
time

● Memory is a very useful resource.


■ Clearly we need a way to request memory on runtime.

■ Dynamic Memory Allocation is a way in which the size of a data structure can be changed
during the runtime.
■ Methods

◆ Malloc --> memory allocation ptr = (int*) malloc (n * sizeof (int));


◆ Calloc --> contiguous allocation ptr = (int*) calloc (n, sizeof (int));
◆ Realloc --> reallocation ptr = (int*) realloc (ptr, n * sizeof (int));
◆ Free --> free the allocated memory free (ptr);

● File Modes-- <stdlib.h>


■ FILE *variable_name;
■ var = Fopen("filename.txt", "mode"); --> Open a file / create a file;
■ variable_name --> return Null when file does not exist
■ Modes
◆ w → Writes to a file / open a file / create a file
◆ a → Appends new data to a file
◆ r → Reads from a file
■ Fclose (variable_name); --> close a file
■ Fprintf (variable_name, "Some text"); --> to write text in opened file
● Fgets (string_variable, 100, variable_name); --> read content from fileEnum --> define
integer in a string form

● Dynamic memory allocation --> <stdlib.h>


■ A statically allocated variable or array has a fixed size in memory.
■ We have learnt to create big enough arrays to fit in our inputs but this doesn't seem like
an optimal way to allocate memory.

You might also like