PPS Syllabus & Notes PDF

Document Details

LovelyHoneysuckle6634

Uploaded by LovelyHoneysuckle6634

IIMT College of Engineering

Tags

C programming programming language computer science programming fundamentals

Summary

This document is a syllabus and notes about C programming. It covers topics such as basic C syntax, including keywords, data types, and comments. It also introduces syntax and logical errors and their difference.

Full Transcript

**/ Documentation** | It is the comment section and is | | | part of the description section | | **// Link** | of the code.  | +-----------------------------------+-----------------------------------+ | **\#i...

**/ Documentation** | It is the comment section and is | | | part of the description section | | **// Link** | of the code.  | +-----------------------------------+-----------------------------------+ | **\#include\** | Header file which is used for | | | standard input-output. This is | | | the preprocessor section. | +-----------------------------------+-----------------------------------+ | **\#define X 20** | This is the definition section. | | | It allows the use of constant X | | | in the code. | +-----------------------------------+-----------------------------------+ | **int sum(int y)** | This is the Global declaration | | | section includes the function | | | declaration that can be used | | | anywhere in the program. | +-----------------------------------+-----------------------------------+ | **int main()** | main() is the first function that | | | is executed in the C program. | +-----------------------------------+-----------------------------------+ | **{...}** | These curly braces mark the | | | beginning and end of the main | | | function.  | +-----------------------------------+-----------------------------------+ | **printf("Sum: %d", sum(y));** | printf() function is used to | | | print the sum on the screen. | +-----------------------------------+-----------------------------------+ | **return 0;** | We have used int as the return | | | type so we have to return 0 which | | | states that the given program is | | | free from the error and it can be | | | exited successfully. | +-----------------------------------+-----------------------------------+ | **int sum(int y) \ | This is the subprogram section. | | {\ | It includes the user-defined | |  return y + X;\ | functions that are called in the | | }** | main() function. | +-----------------------------------+-----------------------------------+ 9\. **Distinguish between Syntax error and Logical error.** **Syntax Errors** **Logical Errors** ------------------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------- Syntax Errors occur when we violate the rules of writing the statements of the programming language. Logical Errors occur due to our mistakes in programming logic. Program fails to compile and execute. Program compiles and executes but doesn\'t give the desired output. Syntax Errors are caught by the compiler. Logic errors need to be found and corrected by the people working on the program. 10\. Define all: a. **Keyword** b. **Comment** c. **Data type** d. **Statement** (a)A keyword is a **reserved word**. You cannot use it as a variable name, constant name, etc. There are only 32 reserved words (keywords) in the C language. A list of 32 keywords in the c language is given below: auto break case char const continue default do -------- -------- ---------- -------- ---------- ---------- ---------- -------- double else enum extern float for goto if int long register return short signed sizeof static struct switch typedef union unsigned void volatile while **(b)Comment** Comment is that which inactivate any line in the program. There two type of comment. 1. [Single line comment(//)] It is that which inactive any one line. **Example** // x=y; //y=z; //Z=v; 2. [Multiline comment(/\*......................\*/)] It is that which inactive one or more than one line. /\* X=y; Y=z; Z=v; \*/ c. **Data type** Data type is that which reserve the size inside the memory of any variable. There is no other method to reserve the size inside the memory. **Data type** **Primitive Non primitive or user define or derive type** Numeric non numeric Array,struct etc Int,double char **Type** **Size (bytes)** **Format Specifier** ------------------------------- ---------------------------------- ---------------------- int at least 2, usually 4 \%d, %i char 1 \%c float 4 \%f double 8 \%lf short int 2 usually \%hd unsigned int at least 2, usually 4 \%u long int at least 4, usually 8 \%ld, %li long long int at least 8 \%lld, %lli unsigned long int at least 4 \%lu unsigned long long int at least 8 \%llu signed char 1 \%c unsigned char 1 \%c long double at least 10, usually 12 or 16 \%Lf **Type** **Range** **Size (in bytes)** unsigned char 0 to 255 1 signed char or char -128 to +127 1 unsigned int 0 to 65535 2 signed int or int -32,768 to +32767 2 unsigned short int 0 to 65535 2 signed short int or short int -32,768 to +32767 2 unsigned long int 0 to +4,294,967,295 4 signed long int or long int -2,147,483,648 to +2,147,483,647 4 long double 3.4E-4932 to 1.1E+4932 10 double 1.7E-308 to 1.7E+308 8 float 3.4E-38 to 3.4E+38 4 **d)** Statement There is 4 types of statement :- i. iii. iv. 11\. What is storage class? Define all storage class with example. **Storage Class-Storage class is that which store the data In a special memory which can be access fastly** **Types of Storage Classes in C** There are four different types of storage classes that we use in the C language: - **Automatic Storage Class** - **External Storage Class** - **Static Storage Class** - **Register Storage Class** **Use of Storage Class in C** A variable given in a C program will have two of the properties: storage class and type. Here, type refers to any given variable's data type, while the storage class determines that very variable's lifetime, visibility, and also its scope. **Summary of Storage Classes in C** **Class** **Name of Class** **Place of Storage** **Scope** **Default Value** **Lifetime** ----------- ------------------- ---------------------- ----------- ------------------- ---------------------------------------------------------------------------------- Auto Automatic memory Local Garbage Value As long as the program control remains within the block in which it is declared. extern External memory Global Zero Till the main program ends. One can declare it anywhere in a program. static Static memory Local Zero Till the main program ends. It contain the current value. register Register Register Local Garbage Value As long as the program control remains within the block in which it is declared Example auto or static or register Void main() { auto int x=10; printf("x=%d",x);} Example of extern: extern int x=10; 12. What is a variable in C? ---------------------------- *A **variable in C **is a memory location with some name that helps store some form of data and retrieves it when required. We can store different types of data in the variable and reuse the same variable for storing some other data any number of times.* **Rules for Naming Variables in C** **You can assign any name to the variable as long as it follows the following rules:** 1. 1. 1. 1. **C Variable Types** The C variables can be classified into the following types: 1. 1. 1. 1. 1. 1. ** [Local Variables ]** ----------------------------------- A **Local variable in C** is a variable that is declared inside a function or a block of code. Its scope is limited to the block or function in which it is declared. [Global Variables ] ------------------------------- A **Global variable in C **is a variable that is declared outside the function or a block of code. Its scope is the whole program i.e. we can access the global variable anywhere in the C program after it is declared. **[UNIT-2]** 1. What is operator.Define different type of operator use in C. Ans: An operator in C can be defined as the symbol that helps us to perform some specific mathematical, relational, bitwise, conditional, or logical computations on values and variables. ![Lightbox](media/image70.png) **Types of Operators in C** C language provides a wide range of operators that can be classified into 6 types based on their functionality: 1. 1. 1. 1. 1. 1. 1. Arithmetic Operator \+ \- \* / \% (modulus) Ex: x=10,y=3 K1=x/y; K2=x%y; K1=3 (quiescent) K2=1 (remainder) 2. Relational Operators \> \< \>= \10 && a\10 && a\ 4. Post fix and prefix op(Unary op): Postfix : First assignment then increment or decrement. X++ y--- Prefix : First increment or decrement then assinment. ++X \--y X++ Or x=x+1 ++x x--- or x=x-1 \--x Example X=10 y=5 K1=x++ k3=\--y K2=x k4=y Result K1=10 k3=4 K2= 11 k4=4 5. Assinment op: += -= \*= /= \%= = Example x=10,y=20 x+=y; Or x=x+y; Result x=30 6. Ternary op: ?: ; Example X=10 Y=20 Z=(x\y) ? x : y; Result Z=20 7. Cast op: In typing casting, a data type is converted into another data type by the programmer using the casting operator during the program design. In typing casting, the destination data type may be smaller than the source data type when converting the data type to another data type. 8. Bitwise op: The Bitwise operators are used to perform bit-level operations on the operands. The operators are first converted to bit-level and then the calculation is performed on the operands. Different type of bitwise op 1. Bitwise and & 2. Bitwise or \| 3. Bitwise x\_or \^ 4. Bitwise left shift \\> Bitwise and & Op bit op result 5 101 & & 4 6 110 \-\-\-\-\-\-\-\-\-\-\-\-\-- 100 [ Bitwise and \|] Op bit op result 5 101 \| \| 7 6 110 \-\-\-\-\-\-\-\-\-\-\-\-\-- 111 [Bitwise x\_or \^] Op bit op result 9 1001 \^ \^ 3 10 1010 \-\-\-\-\-\-\-\-\-\-\-\-\-- 0011 Bitwise left shift(\y; I 0000 1010 II 000 0000 1010 III 1 ^Z\ =\ 1^ PS- Define all control statement with example^.^ ans: There are two type of control statement 1. If-else 2. Switch 1)If-else- it is a control statement which is use for checking the condition if condition is true then do the statement 1 if false then go to the else part and do the statement 2. Syntax if(condition) { Statement 1; } else { Statement 2; } 3. Switch- it is also a control statement which is use to check the multiple cases in one time. in this we cannot use any condition only expression.it map with the different cases if satisfy then do this case and come back by break statement.if not satisfy then do the default work.

Use Quizgecko on...
Browser
Browser