Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Overig

PRACTICE QUESTIONS FOR EXAM FROM UNIT 1 AND 2 INTRO TO COMPONENTS TO COMPUTER SYSTEM AND IDEA OF ALGORITHM

Beoordeling
-
Verkocht
-
Pagina's
7
Geüpload op
27-06-2025
Geschreven in
2024/2025

QUESTIONS FOR PRACTICE FOR C PROGRAMMING OPERATORS IN C, EXAMPLES ,DATATYPES, IF ELSE STATEMENTS. ETC

Instelling
Vak

Voorbeeld van de inhoud

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​

, ○​ Example: For int a = 9, b = 3, c = 0; 24​

■​ Multiply (*): c = a * b; (Result: 27) 25​

■​ Divide (/): c = a / b; (Result: 3) 26​

■​ Addition (+): c = a + b; (Result: 12) 27​

■​ Subtraction (-): c = a - b; (Result: 6) 28​

■​ Modulus (%): c = a % b; (Result: 0) 29​

●​ Relational Operators (Comparison Operators): These compare two values and return
true (1) or false (0) based on the relationship30.​

○​ Example: x < y returns true if x is less than y, otherwise false. 31​

■​ Less than (<): 3 < 5 (Output: True [1]) 32​

■​ Greater than (>): 7 > 9 (Output: False [0]) 33​

■​ Less than or equal to (<=): 100 <= 100 (Output: True [1]) 34​

■​ Greater than or equal to (>=): 50 >= 100 (Output: False [0]) 35​

●​ Equality Operators: C supports two types for strict equality or inequality. 36​

○​ Equal to (==): Returns 1 (True) or 0 (False). 37​

○​ Not equal to (!=): Returns 1 (True) or 0 (False). 38​

●​ Logical Operators:
○​ Logical AND (&&): Returns true if both operands are true. 39​

■​ Truth Table: 40​


| A | B | A&&B |​
|---|---|---|​
| 0 | 1 | 0 |​

, | 1 | 0 | 0 |​
| 0 | 0 | 0 |​
|1|1|1|
○​ Logical OR (||): Returns false only if both operands are false. 41​

■​ Truth Table: 42​


| A | B | A||B |​
|---|---|---|​
| 0 | 1 | 1 |​
| 1 | 0 | 1 |​
| 0 | 0 | 0 |​
|1|1|1|
○​ Logical NOT (!): Takes a single expression and negates its value. 43​

■​ Truth Table: 44​


| A | !A |​
|---|---|​
| 0 | 1 |​
|1|0|
●​ Unary Operator (Unary Minus): Different from binary operators because it operates on
only one operand. 45​

○​ Example: int a, b = 10; a = -(b); results in a = -10; 46​

●​ Conditional Operator: Similar to an if-else statement, used within an expression. 47​

●​ Bitwise Operators: Perform operations at the bit level. 48​

○​ Bitwise AND
○​ Bitwise OR
○​ Bitwise NOT
●​ Assignment Operator (=): Responsible for assigning values to variables. 49​

○​ Example: int x = 10; This assigns the value 10 to variable x. 50​

, 2. Data Types:



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


●​ 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). 58These 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​

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
27 juni 2025
Aantal pagina's
7
Geschreven in
2024/2025
Type
OVERIG
Persoon
Onbekend

Onderwerpen

$7.89
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
muskanbhatoya

Maak kennis met de verkoper

Seller avatar
muskanbhatoya CHANDIGARH GROUP OF COLLEGES
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
10 maanden
Aantal volgers
0
Documenten
13
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen