Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

PROGRAMMING IN C ( PRACTICE ASSIGNMENT1 FOR EXAMS)(BTPS101-18), Study notes of C programming

THIS NOTES INCLUDES QUESTIONS WITH ANSWERS AND TOPIC INCLUDES OPERATORS IN C, DATATYPES SIZE AND RANGES,COMPILATION PROCESS IN C, ALGORITHM AND PSEUDOCODE, PROGRAM FOR IF- ELSE STATEMENT. MY NOTES ARE EASY TO UNDERSTAND AND IS REASONABLE WITH THE PRICE. CHECK IT OUT .

Typology: Study notes

2024/2025

Available from 07/04/2025

KANOYA2786
KANOYA2786 🇮🇳

9 documents

1 / 7

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PROGRAMMING FOR PROBLEM SOLVING(C)
Assignment Questions For Practice (TOPICS-
OPERATORS,DATATYPES,INTRO TO PROGRAMMING,IF ELSE
STATEMENT)
1. List different types of operators in C with examples. 1
2. What is a data type? List the size and range of basic data types.
5
3. Illustrate the compilation process in C. 9
4. Compare algorithm and pseudocode. 13
16
5. Construct a program for an if-else statement. 17
Solutions:-
1. Operators in C:
An operator is a special symbol that tells the compiler to perform specific mathematical,
logical, or relational operations. C language offers various types of operators used with
variables and constants to create expressions21. These operators are grouped into major
categories: 22
Arithmetic Operators: These perform mathematical calculations. 23
pf3
pf4
pf5

Partial preview of the text

Download PROGRAMMING IN C ( PRACTICE ASSIGNMENT1 FOR EXAMS)(BTPS101-18) and more Study notes C programming in PDF only on Docsity!

PROGRAMMING FOR PROBLEM SOLVING(C)

Assignment Questions For Practice (TOPICS-

OPERATORS,DATATYPES,INTRO TO PROGRAMMING,IF ELSE

STATEMENT)

  1. List different types of operators in C with examples.^1
  2. What is a data type? List the size and range of basic data types. 5
  3. Illustrate the compilation process in C.^9
  4. Compare algorithm and pseudocode.^13 16
  5. Construct a program for an if-else statement.^17

Solutions:-

1. Operators in C:

An operator is a special symbol that tells the compiler to perform specific mathematical, logical, or relational operations. C language offers various types of operators used with variables and constants to create expressions^21. These operators are grouped into major categories: 22

Arithmetic Operators: These perform mathematical calculations. 23

● Relational Operators (Comparison Operators): These compare two values and return

| A | B | A&&B |

|---|---|---|

 - ○ Example: For int a = 9, b = 3, c = 0; - ■ Multiply (*): c = a * b; (Result: 27) - ■ Divide (/): c = a / b; (Result: 3) - ■ Addition (+): c = a + b; (Result: 12) - ■ Subtraction (-): c = a - b; (Result: 6) - ■ Modulus (%): c = a % b; (Result: 0) 
  • true (1) or false (0) based on the relationship
    • ○ Example: x < y returns true if x is less than y, otherwise false.
      • ■ Less than (<): 3 < 5 (Output: True [1])
      • ■ Greater than (>): 7 > 9 (Output: False [0])
      • ■ Less than or equal to (<=): 100 <= 100 (Output: True [1])
      • ■ Greater than or equal to (>=): 50 >= 100 (Output: False [0])
  • ● Equality Operators: C supports two types for strict equality or inequality. - ○ Equal to (==): Returns 1 (True) or 0 (False). - ○ Not equal to (!=): Returns 1 (True) or 0 (False). - ○ Logical AND (&&): Returns true if both operands are true. ● Logical Operators: - ■ Truth Table:

2. Data Types:

A data type tells you what kind of data value is stored in a variable^51. The data type of a variable is specified when it's declared and remains until the program finishes executing^52.

Categories of Data Types:^53

Primary: int, char, float 54

Secondary: Structure, Array, Pointer 55

Size and Range of Basic Data Types:^56

| DATATYPE | SIZE | RANGE |

| unsigned int | 2 bytes | 0 to 65,535 | | int | 2 bytes | -32768 to 32767 | | Long int | 4 bytes | -2147483648 to 2147483647 | | Short int | 2 bytes | -32768 to 32767 | | Float | 4 bytes | 1.2E−38 to 3.4E+38 | | char | 1 byte | -128 to 127 | | unsigned char | 1 byte | 0 to 255 |

3. Compilation Process in C:

The compilation process involves several steps to transform your source code into an executable program: 57

  1. Source File (.c): This is where you write your program instructions in a high-level language (like C). 58 These are essentially commands given to the compiler to achieve a specific task. 59
  2. Header Files (.h): These contain pre-defined standard library functions. 60
  3. Compiler: This is a special program that translates your source code (written in C) into machine language (0s and 1s), which is called object code. 61
  1. Object File: This file contains the machine code generated by the compiler. 62
  2. Linker: This program combines object modules (especially important for large programs broken into smaller parts) to form a single executable program. It also checks the source code for errors. 63
  3. Executable File: This is the final computer file containing code that can be directly run by the computer. 64
  4. Loader: This program copies the executable program from the storage device into the main memory, where the CPU can then run and execute it. 65656565

4. Algorithm and Pseudocode Comparison:

ALGORITHM PSEUDOCODE

A step-by-step procedure to solve a problem. 66

A high-level language. 67

Defines the logic and approach to a problem. 68

An independent representation of an algorithm. 69

It is independent of any programming language but resembles code. 70

It is described using natural language or structured steps, without being tied to any specific syntax of a programming language. 71

It helps in planning before coding by providing a structured outline. 72

It cannot be directly executed by a computer but can be easily translated into actual code. 73

● If you enter 20: Entered number is even ● If you enter 59: Entered number is odd