0% found this document useful (0 votes)
4 views5 pages

C Programming Concepts and Control Structures

The document provides an overview of fundamental programming concepts in C, including pseudocode, variables, constants, keywords, tokens, and data types. It explains control structures like if statements, switch cases, loops, and the differences between compilation and execution. Additionally, it discusses algorithm characteristics, time and space complexity, and the distinctions between break and continue statements.

Uploaded by

srisanthkatta56
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)
4 views5 pages

C Programming Concepts and Control Structures

The document provides an overview of fundamental programming concepts in C, including pseudocode, variables, constants, keywords, tokens, and data types. It explains control structures like if statements, switch cases, loops, and the differences between compilation and execution. Additionally, it discusses algorithm characteristics, time and space complexity, and the distinctions between break and continue statements.

Uploaded by

srisanthkatta56
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

UNIT 1

Short Answer Quesions


1) What is pseudo code? Example with an example.
1. Pseudocode is a simplified, informal way of describing a program's logic or algorithm
using plain English.
2. It is not actual code but serves as a bridge between the problem statement and the final
implementation in a programming language like C.
3. Pseudocode helps programmers plan and visualize the structure of their code before writing it,
making it easier to understand and debug.
Example:

START

Input three numbers: num1, num2, num3

IF num1 > num2 AND num1 > num3 THEN

largest = num1

ELSE IF num2 > num1 AND num2 > num3 THEN

largest = num2

ELSE

largest = num3

ENDIF

Print "The largest number is", largest

END

2) Define key words constants and variables

Variables in C:A variable is a named storage location in memory used to hold data. It allows
programmers to reference memory locations using meaningful names instead of numeric addresses.

Constants in C:A constant is a value that cannot be changed during the program's execution.
Constants are declared using the const keyword or the #define preprocessor directive.

Keywords in C:Keywords are reserved words in C that have predefined meanings and cannot be used
as variable names. They instruct the compiler on how to interpret the code.

3) What are c Tokens? How many types are there?

Ans) Tokens are the smallest enduvidual unit of a C programm. There are four types

1. Key words or reserve words


2. Identifiers
3. Constants
4. Opetrators
4. Define program counter? What are per-processer Directives.

Ans) The Program Counter (PC) is a special-purpose register in a processor that


holds the memory address of the next instruction to be [Link]
directives are represented by symbol (#) . There are three types of perprocessor
directives
1. Macro Substitution Directives
2. File Inclusion Directives
3. Conditional Compilation Directives.
5. What are primitive data types? Give examples.
Ans) Primary data types are also knows as primitive data [Link] are three
types.
Examples are:
1. Integer (int)
2. Character (char)
3. Floating-point (float)

6) What is type casting?


Ans) Typecasting in C refers to the process of converting one data type into
another. It is a crucial concept that allows programmers to handle data more
flexibly and efficiently.
7) Define Algorithm? Write any two characteristics of an algorithm.

Ans) Definition of Algorithm:

An algorithm is a step-by-step procedure or a set of well-defined instructions


designed to solve a specific problem or perform a task. It takes inputs, processes
them through a sequence of steps, and produces an output.

Two Characteristics of an Algorithm in C Language:

Finiteness:

An algorithm must always terminate after a finite number of steps. It cannot run
indefinitely and must produce a result within a reasonable time.

Definiteness:

Each step of the algorithm must be clearly and unambiguously defined. There
should be no confusion about what needs to be done at any stage.
8) What is the difference between compilation and execution?
Ans)

Compilation execution
Compilation is the process of Execution is the process of running
converting the human-readable the compiled program on the
source code (written in C) into computer's processor.
machine-readable code (binary or
object code).
It checks for syntax errors and It performs the actual tasks defined in
ensures the code adheres to the rules the program, such as calculations,
of the C language. input/output operations, or interacting
with hardware.
A compiler (e.g., GCC, Clang) The operating system and processor
performs this task. handle execution.
The compiler generates Produces the program's results, such
an executable file (e.g., .exe on as printed output, file modifications,
Windows or an [Link] file on Linux). or other actions.

9) State one advantage of Top-down approach.


Ans) The top-down approach in programming involves breaking down a complex
problem into smaller, more manageable sub-problems. This hierarchical
decomposition continues until each sub-problem is simple enough to be solved
independently.
10) Define time complexity and space complexity.
Ans) Time complexity: Tells us how much time an algorithm will take to run as
the input size increases.
Space complexity: Tells us how much memory an algorithm uses. It includes:
Variables
Data structures (arrays, linked lists, etc.)
Function call stack (especially in recursion)

UNIT 2
1)Explain significance of if statement in c.
Ans) The if statement is a decision-making statement that allows a program
to execute certain code only when a specific condition is true. It helps control the
flow of execution based on logical conditions.
2) Describe switch case statement with syntax.
Ans) The switch statement allows a variable to be tested for equality against a
list of values (called cases).It is an alternative to using multiple if-else-if
statements.
3) Explain about while loop.
Ans) A while loop repeatedly executes a block of code as long as the given
condition is [Link] condition is checked before the loop body executes
(entry-controlled loop).
4) Explain working of continue statement.
Ans) The continue statement is used inside [Link] skips the remaining
code in the current iteration and jumps to the next iteration of the loop.
5) Define break statement.
Ans) The break statement is used to terminate the loop or switch statement
[Link] is transferred to the statement following the loop or switch.
6) Describe do-while with suitable example
Ans) The do-while loop is similar to a while loop, but the condition is checked
after executing the loop [Link] ensures the loop body runs at least once.
7) Compare while and do-while.
Ans)

Feature while loop do-while loop

Condition
Before loop body After loop body
Checking

May not execute if condition is Executes at least


Execution
false once

Type Entry-controlled loop Exit-controlled loop

8) Explain working of continue statement.


Ans) The continue statement is used inside [Link] skips the remaining
code in the current iteration and jumps to the next iteration of the loop.
9) Compare if-else-if with switch.
Ans)

Feature if-else-if switch

Condition Can test logical or relational Tests equality of a single


Type expressions variable

Works with int, char, enum (not


Data Types Works with int, float, char, etc.
float or string)

Less readable for many


Readability More readable and organized
conditions

Default else part (optional) default case (optional)


Feature if-else-if switch

Execution

10) Differentiate between break and continue.


Ans)

Feature Break continue

Terminates the loop or switch Skips to the next iteration of the


Function
completely loop

Control Returns to loop condition


Exits the loop
Flow checking

Common in switch, for, while, do-


Usage Used only inside loops
while

You might also like