Sikshya Plus Get appGet the app free
Class 11 · Computer Science

Programming Concepts & Logics – Class 11 Computer Science Notes and Solutions

Complete solutions and answers for “Programming Concepts & Logics”, a chapter in Class 11 Computer Science (NEB exam preparation). This page covers Section 1 — Multiple Choice Questions (MCQs), Section 2 — Short Answer Questions and Section 3 — C Programming Exercises.

  • Free, no login needed
  • 25 min read
  • Updated 1 July 2026

Chapter at a glance

This chapter covers programming concepts and logic, including programming languages, control structures, flowcharts, pseudocode, and the C language. It introduces the basics of programming, data types, variables, operators, and control structures. The chapter provides a foundation for understanding how to write programs and solve problems using a programming language.

  • Programming Languages
  • Control Structures
  • Flowcharts
  • Pseudocode
  • C Language
  • Data Types
  • Variables
  • Operators

Exam focus: Students should focus on understanding the basics of programming, including data types, variables, operators, and control structures, as well as being able to write simple programs in the C language.

Key formulas and definitions

  • Algorithm = Logic + Control Structure
  • Pseudocode = Natural Language + Programming Constructs
On this page (3 sections)
  1. Section 1 — Multiple Choice Questions (MCQs)
  2. Section 2 — Short Answer Questions
  3. Section 3 — C Programming Exercises

Solutions and answers

Section 1 — Multiple Choice Questions (MCQs)

a A computer understands ……… language directly.
  • Fourth generation
  • First generation
  • Second generation
  • Third generation
ii) First generation
First generation language is machine language — the only language a computer can understand and execute directly. It consists of binary digits (0s and 1s). All other languages (assembly, high-level, 4GL) must be translated into machine language before execution.
b ……… language is machine dependent language.
  • Machine level
  • Assembly
  • High level
  • Fourth generation
i) Machine level
Machine language is machine dependent — it is specific to the processor architecture. A program written in machine language for one type of CPU cannot run on a different type of CPU. High-level languages are machine independent.
c Which programming language uses mnemonic codes?
  • Assembly language
  • 4th generation
  • Machine language
  • High level language
i) Assembly language
Assembly language uses mnemonic codes (abbreviated English-like words) to represent machine operations. Examples: MOV (move), ADD (add), SUB (subtract), JMP (jump). These are easier for programmers to remember than pure binary codes.
d A ……… converts programs in assembly language into machine language.
  • Assembler
  • Interpreter
  • Compiler
  • None of the above
i) Assembler
An Assembler is the language processor that translates assembly language (source code) into machine language (object code). A Compiler translates high-level languages, and an Interpreter also works with high-level languages but executes line-by-line.
e An error in programming code is referred as
  • GIGO
  • Semantic error
  • Syntax error
  • Runtime error
ii) Syntax error
A syntax error is a violation of the grammatical rules of a programming language — such as missing semicolons, unmatched brackets, or incorrect keywords. These are detected by the compiler/interpreter during compilation. GIGO (Garbage In, Garbage Out) is a principle, not an error type.
f IF statement is the example of ……… structure.
  • Selection
  • Sequence
  • Iteration
  • None of the above
i) Selection
The IF statement is a selection (decision/branching) structure. It allows the program to choose between different paths based on whether a condition is true or false. Sequence executes statements in order, and Iteration (loop) repeats statements (e.g., for, while).
g A program design tool that uses simple language to write the set of instructions to solve a problem is
  • Algorithm
  • Flowchart
  • Pseudocode
  • None of the above
iii) Pseudocode
Pseudocode uses a mix of simple English-like language and programming constructs (IF, THEN, ELSE, WHILE, FOR, etc.) to describe algorithmic steps. An algorithm is a step-by-step procedure, and a flowchart uses graphical symbols — neither uses the pseudo-programming language style.
h Which is the basic data type in C language?
  • double
  • float
  • char
  • All of the above
iv) All of the above
C language has four fundamental (basic) data types: int (integer), float (floating-point), double (double-precision floating-point), and char (character). All three listed options are basic data types in C.
i Which of the following statement is not used for selection structure in C program?
  • if
  • switch…case
  • for loop
  • None of the above
iii) for loop
for loop is an iteration (repetition/looping) structure — not a selection structure. if and switch…case are both selection (decision-making) structures used to execute different code based on conditions.
j In BCD, each decimal digit is expressed in the group of ……… bits.
  • 4
  • 6
  • 8
  • 2
i) 4
BCD (Binary Coded Decimal) represents each decimal digit (0–9) using 4 bits. For example, 5 = 0101, 9 = 1001. The number 25 would be represented as 0010 0101 (two groups of 4 bits). This requires 4 bits per digit, allowing 16 combinations (0000–1111) for 10 digits.
k Unicode uses ……… bit numbers.
  • 8
  • 16
  • 32
  • 64
ii) 16
Unicode uses 16-bit encoding (in its basic form, UTF-16), allowing it to represent up to 2¹⁶ = 65,536 unique characters. This covers virtually all writing systems worldwide, including Nepali (Devanagari), Chinese, Arabic, emoji, and more. (Note: UTF-8 uses 8-bit units but is variable-length.)
l A preprocessor must begin with ……… symbol or sign.
  • &
  • *
  • #
  • %
iii) #
In C language, preprocessor directives begin with the hash symbol (#). Examples: #include, #define, #undef, #ifdef. These directives are processed before compilation by the preprocessor.
m An identifier in C language can have
  • lowercase letters
  • number
  • underscore
  • All of the above
iv) All of the above
An identifier (name of variables, functions, arrays) in C can contain: uppercase letters (A–Z), lowercase letters (a–z), digits (0–9), and underscores (_). However, it must begin with a letter or underscore — it cannot start with a digit. C is case-sensitive (Age ≠ age).
n A global variable in C program is
  • declared before the main() function
  • used in main() function
  • used in sub function
  • All of the above
iv) All of the above
A global variable is declared outside all functions (typically before main()). It has global scope, meaning it can be accessed and modified by any function in the program — both main() and all sub-functions. Its lifetime is the entire program execution.
o ……… format specifier is used to print integer number.
  • %c
  • %i
  • %d
  • %f
iii) %d
%d is the standard and most commonly used format specifier for integers in C (printf and scanf). %i also works for integers (especially with scanf for detecting octal/hex input). %c is for characters, and %f is for float/double.

Section 2 — Short Answer Questions

a What is a programming language? Describe the types of programming languages.
Definition: A programming language is a set of instructions, syntax rules, and commands used by programmers to communicate with a computer and give it specific tasks to perform. It serves as an interface between humans and machines, allowing us to write programs that solve problems, process data, and automate tasks.

Types of Programming Languages:

  • Machine Language (1st Generation): Written in binary (0s and 1s). Directly understood by the CPU. Machine-dependent, fast execution, but extremely difficult for humans to read and write.
  • Assembly Language (2nd Generation): Uses mnemonic codes (e.g., MOV, ADD, JMP) instead of binary. Requires an Assembler to convert to machine language. Low-level, machine-dependent, but easier than machine language.
  • High-Level Language (3rd Generation): Uses English-like syntax (e.g., C, Java, Python, C++). Machine-independent, portable, easier to learn and write. Requires a compiler or interpreter for translation.
  • Fourth Generation Language (4GL): Very close to human language. Used for specific purposes like database queries (SQL), report generation, and GUI development. Minimal coding required.
  • Fifth Generation Language (5GL): Based on artificial intelligence and constraint-based programming. The programmer defines the problem, and the language finds the solution. Examples: Prolog, LISP, Mercury.
b What is machine language? Write its advantages and disadvantages.
Definition: Machine language (also called machine code or 1GL) is the lowest-level programming language consisting entirely of binary digits (0s and 1s). It is the only language that a computer's CPU can directly understand and execute without any translation. Each instruction is a specific pattern of bits corresponding to a hardware operation.

Advantages

  • Direct Execution: No translator needed — the CPU executes binary instructions directly, making it the fastest executing language.
  • Efficient Memory Use: Programs can be optimized to use minimal memory since the programmer controls every bit.
  • Hardware Control: Provides complete control over hardware resources — used in embedded systems, device drivers, and firmware.
  • No Translation Overhead: No compiler or assembler is needed, eliminating translation time.

Disadvantages

  • Extremely Difficult: Writing and reading raw binary (e.g., 10110000 01100001) is tedious, error-prone, and impractical for humans.
  • Machine Dependent: Programs are specific to a particular processor — code for one CPU won't work on another.
  • Difficult to Debug: Finding and fixing errors in binary code is extremely challenging.
  • Time Consuming: Writing even simple programs requires enormous effort and time.
  • No Portability: Programs cannot be transferred between different computer architectures.
c What is assembly language? Write its advantages and disadvantages.
Definition: Assembly language (2GL) is a low-level programming language that uses mnemonic codes (abbreviated English-like words) and symbolic labels to represent machine instructions. Examples: MOV AX, 5 (move value 5 to register AX), ADD AX, BX (add two registers). It requires an Assembler to translate into machine language.

Advantages

  • Easier than Machine Language: Mnemonic codes (MOV, ADD, SUB) are more readable and memorable than binary.
  • Faster Execution: Produces efficient machine code — nearly as fast as direct machine language.
  • Hardware Access: Provides direct access to hardware components (registers, memory addresses, I/O ports).
  • Less Memory: Assembly programs typically use less memory than high-level language programs.
  • System Programming: Ideal for writing operating system kernels, device drivers, and embedded systems.

Disadvantages

  • Machine Dependent: Each CPU architecture has its own assembly language — programs are not portable.
  • Complex: Still requires understanding of computer architecture, registers, and memory management.
  • Longer Programs: Simple tasks require many lines of code compared to high-level languages.
  • Difficult to Debug: Debugging assembly programs is harder than high-level languages.
  • Requires Assembler: An additional translation step (assembler) is needed before execution.
d What is third generation language? Write its advantages and disadvantages.
Definition: Third Generation Languages (3GL) are high-level programming languages that use English-like syntax and mathematical expressions to write programs. They are machine-independent (portable) and require a compiler or interpreter to translate into machine language. Examples: C, C++, Java, Python, FORTRAN, COBOL, Pascal, BASIC.

Advantages

  • Easy to Learn & Use: English-like syntax makes them accessible and readable by humans.
  • Machine Independent: Programs can run on different computers with little or no modification — high portability.
  • Structured Programming: Support structured programming with functions, loops, conditionals, and modular design.
  • Built-in Functions: Provide rich libraries and built-in functions for common operations.
  • Easier Debugging: Error messages are more descriptive, and debugging tools are available.
  • Faster Development: Programs can be written much faster than in assembly or machine language.

Disadvantages

  • Slower Execution: Programs run slower than assembly/machine language due to translation overhead.
  • Less Hardware Control: Cannot directly access hardware components like assembly language.
  • Requires Translator: Must be compiled or interpreted before execution, adding time and complexity.
  • More Memory: Programs tend to use more memory than equivalent assembly programs.
  • Compiler Dependency: Different compilers may produce slightly different behaviors on different platforms.
e What is fourth generation language? Write its advantages and disadvantages.
Definition: Fourth Generation Languages (4GL) are very high-level languages designed for specific application domains. They are closer to human language than 3GLs and require minimal coding to accomplish tasks. The programmer specifies what to do rather than how to do it. Examples: SQL (database queries), Oracle Forms, Report Generators, Crystal Reports, MATLAB, R.

Advantages

  • Easy to Use: Very close to natural language — minimal coding required. Accessible to non-programmers.
  • Rapid Development: Programs/applications can be developed much faster than with 3GLs.
  • Less Code: A single 4GL statement can replace many lines of 3GL code.
  • Productivity: Dramatically increases programmer productivity for specific tasks.
  • Domain-Specific: Highly optimized for specific tasks like database queries, report generation, or data analysis.

Disadvantages

  • Less Flexible: Designed for specific purposes — not suitable for general-purpose programming.
  • Slower Execution: Often slower than 3GL programs due to higher abstraction levels.
  • Limited Control: Provides less control over hardware and memory management.
  • Proprietary: Many 4GLs are vendor-specific, leading to vendor lock-in.
  • Larger Programs: The generated code may be larger and less efficient than manually written 3GL code.
f What is a language processor? Describe the different language processors used in computer system.
Definition: A language processor (or translator) is a system software that translates programs written in programming languages (other than machine language) into machine language so that the computer can understand and execute them.

Types of Language Processors:

  • Assembler
    • Translates assembly language (source code) into machine language (object code).
    • Replaces mnemonic codes (MOV, ADD) with their binary equivalents.
    • The source file (.asm) is converted to an object file (.obj), then linked to produce an executable (.exe).
    • Example: MASM (Microsoft Assembler), TASM (Turbo Assembler).
  • Compiler
    • Translates the entire source code of a high-level language into machine language (object code) in one go.
    • Reports all errors at once after scanning the whole program.
    • After compilation, the executable file can run independently without the compiler.
    • Execution is fast since the translated code runs directly.
    • Examples: GCC (C compiler), Turbo C, Borland C++, Java Compiler (javac).
  • Interpreter
    • Translates and executes the source code line by line (one statement at a time).
    • If an error is found on a line, it stops execution at that point — remaining lines are not processed.
    • No separate executable file is created — the interpreter must be present every time the program runs.
    • Execution is slower than compiled programs due to line-by-line translation.
    • Easier debugging — errors are reported immediately as each line is processed.
    • Examples: Python interpreter, Ruby, JavaScript, BASIC interpreter.
💡 Note: Modern languages often use a hybrid approach. For example, Java uses a compiler to produce bytecode, which is then executed by the JVM (Java Virtual Machine) interpreter. Python also compiles to bytecode before interpretation.
g Write the difference between interpreter and compiler.
Basis Compiler Interpreter
Translation Translates the entire program at once into machine code. Translates and executes one line at a time.
Speed Faster execution — translated code runs directly. Slower execution — each line is translated at runtime.
Error Detection Displays all errors after scanning the entire program. Stops at the first error encountered.
Output Produces a separate executable file (.exe). No executable file — requires the interpreter every time.
Memory Requires more memory during compilation. Requires less memory (processes one line at a time).
Debugging Harder to debug — errors shown at end. Easier to debug — errors shown immediately.
Execution Compiled program runs independently. Interpreter must be present for execution.
Examples GCC, Turbo C, Java Compiler (javac). Python, Ruby, JavaScript, BASIC.
Optimization Can optimize code during compilation. Limited optimization — processes line-by-line.
h Explain the types of programming errors with examples.

Programming errors (also called bugs) are mistakes in the program code that prevent it from running correctly. The main types are:

  • Syntax Errors (Compilation Errors)
    • Violations of the grammatical rules of the programming language.
    • Detected by the compiler/interpreter during compilation.
    • The program cannot run until all syntax errors are fixed.
    • Examples: Missing semicolon ;, unmatched curly braces {}, misspelled keywords (pritnf instead of printf), incorrect data types.
  • Semantic Errors (Logical Errors)
    • Errors in the logic or meaning of the program — the code is syntactically correct but produces wrong results.
    • The compiler cannot detect these errors — the program runs but gives incorrect output.
    • Examples: Using + instead of * for multiplication, wrong formula (area = 2 * l * b instead of l * b), incorrect loop condition causing infinite loop.
  • Runtime Errors
    • Errors that occur during program execution (at runtime), not during compilation.
    • Usually caused by illegal operations that the computer cannot perform.
    • The program crashes or terminates abnormally.
    • Examples: Division by zero (5/0), accessing an array element beyond its bounds, null pointer dereference, stack overflow, file not found.
⚠️ Key Distinction: Syntax errors prevent compilation. Semantic errors compile fine but give wrong results. Runtime errors crash the program during execution. A programmer must fix all three types to ensure a program works correctly.
i What is a control structure? Describe the control structures used in programs.
Definition: A control structure (or control flow) determines the order in which statements and instructions in a program are executed. By default, programs execute sequentially (line by line), but control structures allow the programmer to alter the flow of execution based on conditions or repetition needs.

Three Fundamental Control Structures:

  • Sequence Structure
    • Statements are executed one after another in a linear, top-to-bottom order.
    • No branching or looping — the simplest form of control flow.
    • Example: First read input → then calculate → then display output.
    • In C: printf("Hello"); → scanf("%d", &a); → sum = a + b;
  • Selection (Decision/Branching) Structure
    • Allows the program to choose between two or more paths based on whether a condition is true or false.
    • Uses: if, if-else, if-else if-else, switch-case statements.
    • Example: Check if a number is positive, negative, or zero → display appropriate message.
  • Iteration (Looping/Repetition) Structure
    • Allows a block of code to be executed repeatedly as long as a specified condition remains true.
    • Uses: for loop, while loop, do-while loop.
    • Example: Display numbers 1 to 10 → for(i=1; i<=10; i++) printf("%d ", i);
    • Types: Counter-controlled loops (known iterations) and sentinel-controlled loops (unknown iterations).
j What is a flowchart? Write the advantages and disadvantages of flowchart.
Definition: A flowchart is a graphical/diagrammatical representation of an algorithm using standard geometric symbols connected by arrows (flow lines). It visually shows the sequence of steps, decisions, and flow of logic in a program. Flowcharts use standardized symbols defined by ANSI/ISO.

Common Flowchart Symbols:

  • Oval (⬭): Start / End (Terminal)
  • Parallelogram (▱): Input / Output
  • Rectangle (▭): Process / Computation
  • Diamond (◇): Decision (Yes/No, True/False)
  • Arrow (→): Flow of control / Direction
  • Circle (○): Connector (for connecting different parts)

Advantages

  • Visual Clarity: Provides a clear, visual representation of the program logic that is easy to understand.
  • Communication: Serves as an effective communication tool between programmers, analysts, and users.
  • Documentation: Acts as excellent program documentation for future reference and maintenance.
  • Easy Analysis: Makes it easier to analyze, identify errors, and debug the logic before coding.
  • Systematic Approach: Encourages systematic and organized thinking about the problem solution.
  • Language Independent: Flowcharts are universal — not tied to any specific programming language.

Disadvantages

  • Time Consuming: Drawing complex flowcharts takes significant time and effort.
  • Complex for Large Programs: Flowcharts become cluttered and hard to manage for large, complex programs.
  • Difficult to Modify: Changing the logic requires redrawing the entire flowchart or significant portions.
  • No Standards for Detail: Different people may draw flowcharts at different levels of detail.
  • Reproduction Issues: Hand-drawn flowcharts can be difficult to reproduce and share electronically.
  • No Direct Execution: Flowcharts cannot be directly converted to executable code — manual coding is still needed.
k What is pseudocode? Write its advantages and disadvantages.
Definition: Pseudocode (meaning "false code") is an informal, high-level description of an algorithm that uses a mixture of simple English language and programming constructs (such as IF, THEN, ELSE, WHILE, FOR, BEGIN, END) to describe the logic of a program. It is not an actual programming language — it cannot be compiled or executed. It focuses on the logic rather than syntax.

Advantages

  • Easy to Write: No strict syntax rules — uses plain English with programming keywords.
  • Language Independent: Can be converted into any programming language easily.
  • Faster than Flowcharts: Quicker to write and modify than drawing flowcharts.
  • Focused on Logic: Concentrates on the algorithm logic without worrying about language-specific syntax.
  • Easy to Understand: Readable by both technical and non-technical people.
  • Easy to Modify: Changes to logic can be made quickly by editing text.

Disadvantages

  • No Standard Format: There is no universal standard — different programmers may write pseudocode differently.
  • No Visual Representation: Lacks the visual clarity that flowcharts provide.
  • Not Executable: Cannot be compiled, tested, or executed directly.
  • Ambiguity: English language can sometimes be vague or ambiguous compared to precise programming syntax.
  • Less Effective for Complex Logic: For very complex algorithms, pseudocode can become harder to follow than flowcharts.
l Write a pseudocode to accept any three numbers and output the largest among them.
PSEUDOCODE Pseudocode to find the largest of three numbers BEGIN READ num1, num2, num3 SET largest = num1 IF num2 > largest THEN SET largest = num2 END IF IF num3 > largest THEN SET largest = num3 END IF PRINT "The largest number is: ", largest END
Explanation: We assume the first number is the largest, then compare it with the second and third numbers. If either is greater, we update the largest variable. This approach works for any three numbers.
m What is Unicode? Why is it necessary in computer system to represent characters?
Definition: Unicode is an international character encoding standard that assigns a unique number (code point) to every character in every writing system in the world. It uses 16-bit (or more) encoding, allowing it to represent up to 65,536 characters in its basic plane (and over 1 million with supplementary planes). Unicode includes characters from scripts like Latin, Devanagari (Nepali), Chinese, Arabic, Cyrillic, Greek, and symbols, emoji, and more.

Why Unicode is Necessary:

  • Limited Capacity of ASCII: ASCII uses only 7 bits (128 characters) — enough for English letters, digits, and basic symbols but cannot represent characters from other languages (Nepali, Chinese, Arabic, etc.).
  • Limited Capacity of Extended ASCII: Extended ASCII uses 8 bits (256 characters) — still insufficient for global character representation.
  • Global Compatibility: Unicode provides a universal standard that works across all platforms, devices, and software — enabling consistent text display worldwide.
  • Multilingual Support: Supports over 143,000 characters from 150+ scripts, making it possible to display text in virtually any language.
  • Consistent Data Exchange: Ensures that text data can be shared and displayed correctly between different systems, applications, and countries.
  • Modern Necessity: With the internet and global communication, a universal encoding system is essential for emails, websites, databases, and software to handle international text properly.
  • Emoji & Symbols: Unicode also includes modern symbols, mathematical operators, and emoji — essential for modern digital communication.
n What is C language? List its advantages.
Definition: C language is a general-purpose, structured, procedural programming language developed by Dennis Ritchie at Bell Laboratories in 1972. It was originally designed for system programming (developing the UNIX operating system). C is a middle-level language — it combines features of both low-level (hardware access, pointers) and high-level (structured programming, portability) languages. It uses a compiler to translate code.

Advantages of C Language:

  • Simple & Efficient: Has a small set of keywords (32 keywords) and straightforward syntax, making it easy to learn.
  • Portable: Programs written in C can be compiled and run on different platforms with little or no modification.
  • Structured Language: Supports structured programming with functions, loops, conditionals, and modular design.
  • Fast Execution: C programs compile directly to machine code, resulting in high performance.
  • Low-Level Access: Provides pointers and direct memory manipulation, allowing hardware-level programming.
  • Rich Library: Offers a vast collection of built-in functions through standard libraries (stdio.h, stdlib.h, math.h, string.h).
  • Extensible: Users can create their own user-defined functions and libraries.
  • Foundation for Other Languages: C++, Java, C#, Python, and many modern languages are based on or influenced by C.
  • Dynamic Memory Allocation: Supports dynamic memory management using malloc(), calloc(), free().
  • Wide Application: Used in operating systems, embedded systems, game development, compilers, databases, and system utilities.
o Define C preprocessor and header file in C language.
C Preprocessor: The C preprocessor is a text processing tool that processes the source code before actual compilation begins. It handles preprocessor directives (lines beginning with #) such as #include, #define, #undef, #ifdef, #ifndef, #if, #else, #endif, and #pragma. The preprocessor performs tasks like:
  • File inclusion: #include inserts the content of header files into the source code.
  • Macro substitution: #define PI 3.14159 replaces all occurrences of PI with 3.14159.
  • Conditional compilation: #ifdef, #ifndef include/exclude code blocks based on conditions.
Header File: A header file is a file with the extension .h that contains function declarations (prototypes), macro definitions, data type definitions, and constants that can be shared across multiple source files. Header files are included using the #include directive.
  • System Header Files: Provided with the C compiler — <stdio.h> (standard I/O), <stdlib.h> (utility functions), <math.h> (math functions), <string.h> (string functions), <conio.h> (console I/O).
  • User-Defined Header Files: Created by the programmer using #include "myfile.h" (with double quotes for local files).
p Describe the data types used in C language.

Data types specify the type and size of data that a variable can hold. C language provides the following data types:

Data Type Keyword Size (bytes) Range Format Specifier
Integer int 2 or 4 -32,768 to 32,767 (2 bytes) %d or %i
Short Integer short int 2 -32,768 to 32,767 %hd
Long Integer long int 4 or 8 -2,147,483,648 to 2,147,483,647 %ld
Float float 4 ±3.4E-38 to ±3.4E+38 %f
Double double 8 ±1.7E-308 to ±1.7E+308 %lf
Character char 1 -128 to 127 (or 0–255) %c
Unsigned Integer unsigned int 2 or 4 0 to 65,535 %u
Long Double long double 10 or 12 Higher precision %Lf
💡 Note: The size of data types may vary depending on the compiler and system architecture (16-bit, 32-bit, or 64-bit). Use the sizeof() operator to check the size on your system.
Q9 Define constant and variable in C language with examples.
Constant: A constant is a value that cannot be changed during program execution. Once defined, its value remains fixed throughout the program.

Types of Constants:

  • Integer Constants: Whole numbers — 10, -25, 0, 1000
  • Floating-Point Constants: Decimal numbers — 3.14, -0.5, 2.5E3 (2500.0)
  • Character Constants: Single characters in single quotes — 'A', '5', '+'
  • String Constants: Sequence of characters in double quotes — "Hello", "Nepal"

Defining Constants:

C Using #define (preprocessor constant) #define PI 3.14159 #define MAX 100 Using const keyword const int AGE = 25; const float TAX_RATE = 0.13;
Variable: A variable is a named memory location that stores a value which can be changed during program execution. It must be declared before use (specifying its data type and name).
C Variable declaration and initialization int age = 20; integer variable float salary = 50000.50; float variable char grade = 'A'; character variable double pi = 3.14159; double variable Changing the value age = 21; value updated — this is valid for variables
Q10 Describe the operators in C language with examples.

Operators are symbols that perform operations on operands (values or variables). C language provides the following types of operators:

Operator TypeDescriptionExamples
Arithmetic Perform mathematical operations + (add), - (subtract), * (multiply), / (divide), % (modulus/remainder)
Relational Compare two values — return 1 (true) or 0 (false) == (equal), != (not equal), >, <, >=, <=
Logical Combine or modify boolean conditions && (AND), || (OR), ! (NOT)
Assignment Assign values to variables =, +=, -=, *=, /=, %=
Increment/Decrement Increase or decrease value by 1 ++ (increment), -- (decrement) — prefix ++x and postfix x++
Bitwise Perform operations on individual bits & (AND), | (OR), ^ (XOR), ~ (complement), << (left shift), >> (right shift)
Conditional (Ternary) Shorthand for if-else condition ? value_if_true : value_if_false
Example: max = (a > b) ? a : b;
sizeof Returns the size of a data type/variable in bytes sizeof(int) → 4, sizeof(char) → 1
Comma Evaluates multiple expressions left to right a = (x=5, y=10, x+y); → a = 15
C — Operator Examples int a = 10, b = 3; Arithmetic printf("Sum: %d\n", a + b); 13 printf("Modulus: %d\n", a % b); 1 Relational printf("%d\n", a > b); 1 (true) Logical printf("%d\n", (a > 5) && (b < 5)); 1 (true) Ternary int max = (a > b) ? a : b; max = 10 Increment a++; a becomes 11 (post-increment) ++a; a becomes 12 (pre-increment)
Q11 Describe the different types of variables in C language.

Variables in C can be classified based on their scope (where they can be accessed) and lifetime (how long they exist):

  • Local Variables
    • Declared inside a function or block (within curly braces {}).
    • Can only be accessed within that function/block — not visible outside.
    • Their lifetime is limited to the execution of that block.
    • Must be initialized before use (contain garbage values if uninitialized).
  • Global Variables
    • Declared outside all functions (typically before main()).
    • Can be accessed by any function in the entire program.
    • Their lifetime is the entire program execution.
    • Initialized to zero by default if not explicitly initialized.
  • Static Variables
    • Declared with the keyword static.
    • Their value persists between function calls — they are not re-initialized each time the function is called.
    • Scope is local to the function, but the value is retained.
    • Initialized to zero by default.
  • Automatic Variables
    • Declared with the keyword auto (default for local variables).
    • Created when the block is entered and destroyed when the block is exited.
    • Contain garbage values if not initialized.
  • External Variables
    • Declared with the keyword extern.
    • Used to access a global variable defined in another file.
    • Does not allocate memory — just declares the variable that exists elsewhere.
  • Register Variables
    • Declared with the keyword register.
    • Stored in the CPU register instead of RAM for faster access.
    • Suitable for variables used frequently (like loop counters).
    • Their address cannot be taken using the & operator.
Q12 Define a format specifier. List the format specifiers with their usages.
Definition: A format specifier is a special sequence of characters (starting with %) used in printf() and scanf() functions to specify the type and format of data to be displayed or read. They act as placeholders that tell the compiler what type of data to expect.
Format SpecifierData TypeUsage
%dintPrint/scan a decimal (signed) integer
%iintPrint/scan an integer (also detects octal/hex in scanf)
%uunsigned intPrint/scan an unsigned integer
%ffloat / doublePrint/scan a floating-point number
%efloat / doublePrint in scientific notation (e.g., 3.14e+02)
%lfdoubleScan a double value (scanf); Print in some compilers
%ccharPrint/scan a single character
%sstring (char[])Print/scan a string of characters
%ppointerPrint a memory address (pointer value)
%ointPrint an integer in octal (base 8)
%x / %XintPrint an integer in hexadecimal (base 16)
%ldlong intPrint/scan a long integer
%Lflong doublePrint a long double value
%%—Print the literal % character
%hdshort intPrint/scan a short integer
C — Examples int a = 25; float b = 3.14; char c = 'A'; printf("Integer: %d\n", a); Output: Integer: 25 printf("Float: %f\n", b); Output: Float: 3.140000 printf("Character: %c\n", c); Output: Character: A printf("Octal: %o\n", a); Output: Octal: 31 printf("Hex: %x\n", a); Output: Hex: 19

Section 3 — C Programming Exercises

5 Write a program in C language to display sum, difference and product of 9 and 12.
C #include <stdio.h> int main() { int a = 9, b = 12; printf("Sum = %d\n", a + b); 21 printf("Difference = %d\n", a - b); -3 printf("Product = %d\n", a * b); 108 return 0; }
Output: Sum = 21, Difference = -3, Product = 108
6 Write a program in C language to display average of 5, 9 and 12.
C #include <stdio.h> int main() { int a = 5, b = 9, c = 12; float avg; avg = (a + b + c) /

Frequently asked questions

What is Programming Concepts & Logics about?

This chapter covers programming concepts and logic, including programming languages, control structures, flowcharts, pseudocode, and the C language. It introduces the basics of programming, data types, variables, operators, and control structures. The chapter provides a foundation for understanding how to write programs and solve problems using a programming language.

Which topics are covered in Programming Concepts & Logics?

Class 11 Computer Science “Programming Concepts & Logics” covers: Programming Languages; Control Structures; Flowcharts; Pseudocode; C Language; Data Types; Variables; Operators.

What should I focus on in Programming Concepts & Logics for the exam?

Students should focus on understanding the basics of programming, including data types, variables, operators, and control structures, as well as being able to write simple programs in the C language.

What are the key formulas or definitions in Programming Concepts & Logics?

Algorithm = Logic + Control Structure; Pseudocode = Natural Language + Programming Constructs.

Where can I read the Class 11 Computer Science “Programming Concepts & Logics” solutions?

Right on this page. They are free and you do not need to sign up. For chapter quizzes and the AI tutor, install the Sikshya Plus app.

Study tips

Free for Class 9 to 12

Do not just read it. Practice it.

You have read the solutions for Programming Concepts & Logics. Now test yourself, ask the AI tutor and keep your streak going.

Sikshya Plus chapter quiz screen with class, subject and difficulty options
Sikshya AI personal tutor chat inside the app
Sikshya Plus AI tools screen: question assistant, summarizer, translator, grammar checker
Chapter list with Past Q, materials, posts and books tabs
  • AI quizzes for this chapterTest yourself with instant feedback and explanations after every answer.
  • AI tutor, free, 24/7Stuck on a question? Ask in your own words and get a step-by-step explanation.
  • 14 AI tools in one appSummarizer, grammar checker, flashcards, essay help, math solver and more.
  • Past questions and notesPast papers and your own notes organized chapter by chapter.
Download free on Google Play Scan with your phone to install