[go: up one dir, main page]

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

Q1) Explain Algorithm With Example. A Set of Instructions, or A Recipe, For Solving A Problem or Performing A Task

The document provides an overview of fundamental programming concepts, including algorithms, flowcharts, data types in C, tokens, character sets, keywords vs identifiers, storage classes, constants, and variable declaration and initialization. It explains algorithms with examples, describes flowchart symbols, and outlines various data types and their classifications. Additionally, it covers the rules for naming identifiers, the differences between static and extern storage classes, and the distinction between literal and symbolic constants.

Uploaded by

surajandhale1600
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)
3 views7 pages

Q1) Explain Algorithm With Example. A Set of Instructions, or A Recipe, For Solving A Problem or Performing A Task

The document provides an overview of fundamental programming concepts, including algorithms, flowcharts, data types in C, tokens, character sets, keywords vs identifiers, storage classes, constants, and variable declaration and initialization. It explains algorithms with examples, describes flowchart symbols, and outlines various data types and their classifications. Additionally, it covers the rules for naming identifiers, the differences between static and extern storage classes, and the distinction between literal and symbolic constants.

Uploaded by

surajandhale1600
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

FPL Assignment 1

Q1) Explain algorithm with example.


An algorithm is a set of instructions, or a recipe, for solving a problem or
performing a task.
Example: Imagine you want to make a cup of tea. Here's an algorithm for that:
Input: Water, tea bag, sugar (optional)
Instructions:
Boil the water.
Pour the hot water into a cup.
Add the tea bag to the cup.
If desired, add sugar.
Let the tea steep for a few minutes.
Remove the tea bag.
Output: A cup of brewed tea.
1. Start
2. Read A and B
3. C=A+B
4. Display C
5. Stop
Q2) Explain flow chart with different symbols.
A flowchart is a visual representation of a process or algorithm, using symbols
to depict steps, decisions, and flow of information.
 Oval (Terminal): Marks the beginning and end of a process.
 Rectangle (Process): Represents a step or action within the process.
 Diamond (Decision): Indicates a decision point where the flow can diverge
based on a condition.
 Parallelogram (Input/Output): Represents data entering or leaving the
process.
 Arrow: Shows the flow of the process from one step to another.
 Circle (Connector): Used to connect different parts of a flowchart, particularly
when a process jumps to another part of the diagram.
Q3) Explain different data types supported in C language.
C language supports several data types that can be broadly classified into the
following categories:
 Basic Data Types:
These are the fundamental data types that form the building blocks for more
complex data structures.
 int: Used to store integer values (whole numbers). It can be signed or unsigned.
 char: Used to store single characters.
 float: Used to store single-precision floating-point numbers (numbers with
decimal points).
 double: Used to store double-precision floating-point numbers, providing higher
accuracy than float.
 void: Represents the absence of a data type. It is commonly used as the return type
of functions that do not return a value.
 Derived Data Types:
These data types are derived from basic data types and include:
 Arrays: Ordered collections of elements of the same data type.
 Pointers: Variables that store memory addresses.
 Functions: Blocks of code that perform specific tasks.
 User-Defined Data Types:
These data types are created by the programmer to suit specific needs:
 struct: A collection of members of different data types grouped under a single
name.
 union: Similar to structures, but all members share the same memory location.
 enum: A set of named integer constants.

Q4) What are the tokens in C.

In C programming, tokens are the smallest units in the source code that have a
meaningful purpose. These are the building blocks from which C programs are
constructed. There are six primary types of tokens in C:

1. Keywords

These are reserved words that have a specific meaning in C and cannot be used
for any other purpose (like variable names). Examples include:

 int, float, return, if, else, while, for, switch, break, etc.

2. Identifiers

Identifiers are names given to various program elements, such as variables,


functions, and arrays. They must begin with a letter (a-z, A-Z) or an underscore
(_) and may contain letters, digits, and underscores. Examples:

 main, num, sum, count

3. Constants

Constants are literal values used directly in the code. They can be numeric
(integer or floating-point), character constants, or string literals. Examples:

 Integer constant: 100, 0, -56


 Character constant: 'a', 'B', '\n'
 String constant: "Hello, World!"

4. Operators

Operators are symbols that perform operations on variables or values. There are
several types of operators in C:
 Arithmetic operators: +, -, *, /, %
 Relational operators: ==, !=, >, <, >=, <=
 Logical operators: &&, ||, !
 Assignment operator: =
 Bitwise operators: &, |, ^, <<, >>
 Increment/Decrement operators: ++, --
 Other operators: sizeof, , (comma), ->, [], etc.

5. Punctuation (Separators)

These tokens are used to separate other tokens and structure the code. They
include:

 Semicolon (;): Used to terminate statements.


 Comma (,): Used to separate items in a list (like function parameters or
variable declarations).
 Period (.): Used for accessing members of a struct (e.g.,
structName.memberName).
 Parentheses (()): Used for grouping expressions, function calls, etc.
 Curly braces ({}): Used to define the body of functions, loops,
conditionals, etc.
 Square brackets ([]): Used for array indexing.

Q5) Explain character set in C.

a character set refers to the collection of characters that can be used in the
source code. It defines the set of symbols, letters, digits, punctuation marks, and
other characters that are available for use in the language.

Types of Characters in C

1. Letter Characters:
o Uppercase: A to Z
o Lowercase: a to z
2. Digit Characters: 0 to 9
3. Punctuation Characters:
o Symbols like !, @, #, $, %, ^, &, *, (, ), ,, . etc.
4. Whitespace Characters:
o Space:
o Tab: \t
o Newline: \n
o Carriage Return: \r
o Form Feed: \f
5. Escape Sequences:
o Characters like \', \", \\, \n, \t are special sequences used to
represent characters that are hard to type directly.

Q6) Explain difference between keyword and identifiers.


Feature Keywords Identifiers
Meaning Reserved words in C User-defined names
Use Define C syntax and logic Name variables, functions, etc.
Modification Cannot be changed Created and modified by programmer
Examples int, return, while total, count, main

Q7) What is identifier and what are rules to be followed for naming identifier.

 Start with a Letter or Underscore (_):

 An identifier must begin with either a letter (uppercase or lowercase) or


an underscore (_).
 Valid: myVariable, _myVar, totalAmount
 Invalid: 1stValue (cannot start with a digit)

 Followed by Letters, Digits, or Underscore:

 After the first character, an identifier can contain any combination of


letters (A-Z, a-z), digits (0-9), and underscores (_).
 Valid: sum1, total_value, x2, _data123
 Invalid: my-variable (hyphen - is not allowed)

 No Reserved Keywords:

 An identifier cannot be a reserved keyword of the programming


language.
 Invalid: if, while, int, return, etc.

 Case Sensitivity:

 Most programming languages are case-sensitive, meaning myVariable,


MyVariable, and MYVARIABLE are considered distinct identifiers.
 Valid: myVariable, MyVariable, myvariable
 Invalid: int and Int (if int is a reserved keyword in a particular language)

 No Special Characters:

 Identifiers cannot contain special characters (like @, $, #, !, etc.), except


for the underscore (_).
 Invalid: total$, my-var
 Valid: total_amount, my_var

 Length Limitations:

 Some languages may impose limits on the length of an identifier, though


many modern languages allow identifiers to be as long as you need.
However, it is advisable to use concise, descriptive names for readability.

 Avoid Starting with a Digit:

 An identifier cannot start with a number (although it can contain numbers


after the first character).
 Invalid: 3dArray
 Valid: array3d

Q8) Explain Static and Extern storage class with example.

Static Storage Class

In C programming, the static storage class is used to maintain the value of a


variable between function calls. A variable declared as static retains its value
even after the function in which it is declared terminates. It is also used to limit
the scope of a variable to the current file or function, making it unavailable
outside that scope.

Extern Storage Class

The extern storage class is used to declare a variable or function that is defined
in another file. It allows multiple files to share the same variable or function.
Essentially, it tells the compiler that the definition of the variable or function is
located elsewhere, usually in another translation unit (another source file).The
key idea is that an extern variable does not create a new variable; it simply
refers to one that has been declared elsewhere.

Q9) Explain constants in details.

 Literal Constants:

 These are raw values written directly in the code.


 Examples: 5, 'A', 3.14, 0xFF
 Literal constants do not have names and are used directly in expressions.

 Symbolic Constants:
 These are constants defined with names to make code more readable.
 They can be created using:
o #define (preprocessor directive)
o const keyword

#define CONSTANT_NAME value


e.g #define PI 3.14159
const type CONSTANT_NAME = value
const double PI = 3.14159;
Q10) What is variable initialization and declaration.

Variable Declaration

Variable declaration is the process of telling the compiler about the type and
name of the variable. When a variable is declared, you're essentially informing
the compiler that you intend to use a variable of a specific type, and it needs to
allocate space in memory for it

int age; // Declare an integer variable named 'age'


float price; // Declare a floating-point variable named 'price'
char letter; // Declare a character variable named 'letter'

Variable Initialization

Variable initialization is the process of assigning a value to a variable at the


time of its declaration. Initialization ensures that the variable starts with a
known value when it is first used

int age = 25; // Initialize the variable 'age' with the value 25
float price = 10.99; // Initialize the variable 'price' with the value 10.99
char letter = 'A';

You might also like