Skip to content
Ananda Technologies Pvt. Ltd.

Programming in C practicals — MSBTE

MSBTE K-scheme Programming in C (312303) — all 25 lab practicals solved. Every question has 3 different tested programs with real output, explanation and viva questions. Tick one answer per question and print your own practical file free.

✅ Solved by Ananda TechnologiesDiplomaSemester 2MSBTE K-schemeCode 312303CO, IF, CM, CW, SE, IH, AN, AI, DS
25
Practicals
33
Questions
99
Tested programs
📝 Build your own practical file in 3 steps
  1. 1. Tick one answer (A, B or C) for the questions you need — one practical or all.
  2. 2. Press Generate PDF at the bottom. First time: free account (asked only once).
  3. 3. Choose Save as PDF in the print window. Print again any time.

💡 Explain buttons are for your understanding — explanations are never printed.

Practical 1Compulsory

Install and study the C programming environment

Aim: Install a C compiler and editor, write the first program, compile it and run it.

QInstall a C development environment and run a "Hello" program.

Showing answer A of 3 · tap A, B or C to see the others

  1. Download "codeblocks-xx.xxmingw-setup.exe" from codeblocks.org (the file with "mingw" includes the GCC compiler).
  2. Run the setup → Next → I Agree → Full installation → Install.
  3. Open Code::Blocks → File → New → Empty file. Save it as hello.c.
  4. Type the program below and press F9 (Build and run).
  5. A black console window shows the output.

Output

Hello, I have installed Code::Blocks!
#include <stdio.h>

int main()
{
    printf("Hello, I have installed Code::Blocks!\n");
    return 0;
}
🎤 Viva questions (5)
Q. What is an IDE?
A. Integrated Development Environment — editor, compiler and debugger in one software.
Q. What is the use of #include <stdio.h>?
A. It includes the header file that declares printf() and scanf().
Q. Why does main() return 0?
A. 0 tells the operating system that the program finished successfully.
Q. What is the extension of a C source file?
A. .c
Q. Name the steps from source code to output.
A. Edit → Preprocess → Compile → Link → Run.

Practical 2

C programs using constants and variables

Aim: Declare variables of different data types, use constants with const and #define, and print their values.

QWrite a C program using constants and variables.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter radius of circle: 7
Area of circle = 153.94
#include <stdio.h>
#define PI 3.14159

int main()
{
    float radius, area;

    printf("Enter radius of circle: ");
🎤 Viva questions (4)
Q. What is a variable?
A. A named memory location whose value can change while the program runs.
Q. Difference between #define and const?
A. #define is replaced by the preprocessor and has no type; const is a typed variable that cannot be changed.
Q. What are the rules for naming a variable?
A. Letters, digits and _ only; cannot start with a digit; no keywords; case sensitive.
Q. Size of int, float and char in GCC?
A. int 4 bytes, float 4 bytes, char 1 byte.

Practical 3Compulsory

Arithmetic operators

Aim: Use +, -, *, / and % to solve arithmetic problems.

QWrite a C program using arithmetic operators to solve the given arithmetic operations.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter two numbers: 17 5
17 + 5 = 22
17 - 5 = 12
17 * 5 = 85
17 / 5 = 3
17 % 5 = 2
#include <stdio.h>

int main()
{
    int a, b;

    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
🎤 Viva questions (4)
Q. List the arithmetic operators in C.
A. + - * / %
Q. What does % do?
A. Gives the remainder of integer division.
Q. What is 7 / 2 in C when both are int?
A. 3, because integer division drops the decimal part.
Q. Can % be used with float?
A. No, % works only with integer operands; use fmod() for decimals.

Practical 4

Implicit and explicit data type conversion

Aim: See how C converts data types automatically (implicit) and how we force a conversion with a cast (explicit).

QWrite a C program using implicit and explicit data type conversion.

Showing answer A of 3 · tap A, B or C to see the others

Output

total + f        = 9.50
total / count    = 3.00 (wrong)
(float) total / count = 3.50 (correct)
#include <stdio.h>

int main()
{
    int total = 7, count = 2;
    float f = 2.5;

    float sum = total + f;            /* implicit: int -> float */
🎤 Viva questions (4)
Q. What is implicit type conversion?
A. Automatic conversion done by the compiler, e.g. int to float in a mixed expression.
Q. What is explicit type conversion?
A. Conversion forced by the programmer using a cast, e.g. (float) x.
Q. What is type promotion?
A. Converting a smaller type to a bigger type (char → int → float → double) to avoid data loss.
Q. What happens when float is cast to int?
A. The decimal part is removed (truncation).

Practical 5Compulsory

Formatted input / output statements

Aim: Accept student details with scanf and print them neatly with printf format specifiers.

QWrite a well-commented C program using formatted I/O: Name, Roll No, Percentage (2 decimals), Date of Birth (DD/MM/YYYY), Branch, College.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter name: Priya
Enter roll number: 23
Enter percentage: 82.456
Enter date of birth (DD/MM/YYYY): 05/08/2007
Enter branch: CO
Enter college: Government Polytechnic Nanded

----- Student Details -----
Name          : Priya
Roll No       : 23
Percentage    : 82.46
Date of Birth : 05/08/2007
Branch        : CO
College       : Government Polytechnic Nanded
#include <stdio.h>

int main()
{
    char name[30], branch[10], college[60];
    int roll, dd, mm, yyyy;
    float percent;
🎤 Viva questions (5)
Q. What is the difference between printf and scanf?
A. printf prints output; scanf reads input from the keyboard.
Q. Why do we use & in scanf?
A. scanf needs the address of the variable to store the value; arrays (strings) already give an address.
Q. What does %.2f mean?
A. Print a float with 2 digits after the decimal point.
Q. How to read a string with spaces?
A. Use %[^\n] in scanf or fgets().
Q. List common format specifiers.
A. %d int, %f float, %lf double, %c char, %s string.

Practical 6Compulsory

Relational and conditional operator

Aim: Compare values with relational operators (<, >, <=, >=, ==, !=) and choose a result with the conditional operator ?:

Q1Program 1: use relational operators.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter two numbers: 12 20
12 <  20 : 1
12 >  20 : 0
12 <= 20 : 1
12 >= 20 : 0
12 == 20 : 0
12 != 20 : 1
#include <stdio.h>

int main()
{
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);

Q2Program 2: use the conditional (ternary) operator.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter two numbers: 45 78
Largest number = 78
#include <stdio.h>

int main()
{
    int a, b, large;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
🎤 Viva questions (4)
Q. List the relational operators.
A. < > <= >= == !=
Q. Difference between = and ==?
A. = assigns a value; == compares two values.
Q. What is the conditional operator?
A. The ternary operator ?: — condition ? expr1 : expr2.
Q. Why is it called ternary?
A. Because it takes three operands.

Practical 7Compulsory

Logical operators

Aim: Combine conditions with logical AND (&&), OR (||) and NOT (!).

Q1Program 1: use logical AND and OR.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter theory and practical marks: 55 32
Result: FAIL
#include <stdio.h>

int main()
{
    int theory, practical;
    printf("Enter theory and practical marks: ");
    scanf("%d %d", &theory, &practical);

Q2Program 2: use logical NOT.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a number: 15
15 is not even, so it is ODD
#include <stdio.h>

int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
🎤 Viva questions (4)
Q. List the logical operators.
A. && (AND), || (OR), ! (NOT).
Q. What is short-circuit evaluation?
A. In a && b, if a is false, b is not checked; in a || b, if a is true, b is not checked.
Q. What does !5 give?
A. 0, because any non-zero value is true and NOT true is false.
Q. Difference between & and &&?
A. & is bitwise AND on bits; && is logical AND on conditions.

Practical 8

Bitwise operators

Aim: Work on the individual bits of numbers with &, |, ^, ~, << and >>.

Q1Program 1: use &, | and ^.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter two numbers: 12 10
12 & 10 = 8
12 | 10 = 14
12 ^ 10 = 6
#include <stdio.h>

int main()
{
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);

Q2Program 2: use ~, << and >>.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a number: 20
20 << 1 = 40 (multiply by 2)
20 << 3 = 160 (multiply by 8)
20 >> 1 = 10 (divide by 2)
20 >> 2 = 5 (divide by 4)
#include <stdio.h>

int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
🎤 Viva questions (4)
Q. List the bitwise operators.
A. & | ^ ~ << >>
Q. What is 5 & 3?
A. 1 (0101 & 0011 = 0001).
Q. Use of left shift?
A. Multiplies a number by powers of 2, e.g. n << 1 = n × 2.
Q. Difference between ~ and !?
A. ~ flips every bit; ! gives 0 or 1 for a whole condition.

Practical 9

Simple if and if...else statement

Aim: Make decisions with if and if...else.

Q1Program 1: use a simple if statement.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter bill amount: 1500
Amount to pay = 1350.00
#include <stdio.h>

int main()
{
    float bill;
    printf("Enter bill amount: ");
    scanf("%f", &bill);

Q2Program 2: use an if...else statement.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a number: -8
-8 is NEGATIVE
#include <stdio.h>

int main()
{
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
🎤 Viva questions (4)
Q. Syntax of if...else?
A. if (condition) { statements } else { statements }
Q. Is a semicolon allowed after if (condition)?
A. It compiles, but it ends the if — the next statement then always runs. It is a common mistake.
Q. When do we need curly braces?
A. When more than one statement belongs to the if or else.
Q. What value does C treat as true?
A. Any non-zero value.

Practical 10Compulsory

Nested if...else and else-if ladder

Aim: Handle many conditions with nested if...else and the else-if ladder.

Q1Program 1: use a nested if...else.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter three numbers: 23 67 41
Largest = 67
#include <stdio.h>

int main()
{
    int a, b, c;
    printf("Enter three numbers: ");
    scanf("%d %d %d", &a, &b, &c);

Q2Program 2: use an else-if ladder (grade of student: Distinction >75, A >60, B >55, Pass >40, Fail <40).

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter percentage: 68.5
Grade: A
#include <stdio.h>

int main()
{
    float per;
    printf("Enter percentage: ");
    scanf("%f", &per);
🎤 Viva questions (4)
Q. What is a nested if?
A. An if statement written inside another if or else block.
Q. What is an else-if ladder?
A. A chain of if, else if, ..., else where only the first true block runs.
Q. What is the dangling else problem?
A. An else always pairs with the nearest unmatched if; braces avoid confusion.
Q. Ladder vs switch?
A. A ladder can test ranges and any condition; switch tests one value against constant cases.

Practical 11Compulsory

Switch statement

Aim: Choose one of many actions using switch, case, break and default.

QDevelop a C program using a switch statement.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter expression (e.g. 8 * 3): 8 * 3
Result = 24.00
#include <stdio.h>

int main()
{
    float a, b;
    char op;
    printf("Enter expression (e.g. 8 * 3): ");
    scanf("%f %c %f", &a, &op, &b);
🎤 Viva questions (4)
Q. Which data types are allowed in switch?
A. Integer types and char (not float or string).
Q. What happens if break is missing?
A. Execution falls through into the next case.
Q. Is default compulsory?
A. No, but it is good practice to handle unexpected values.
Q. Can two cases have the same value?
A. No, it gives a compile error.

Practical 12Compulsory

Month name from number using switch

Aim: Print the English month name for a number 1–12 using switch.

QWrite a C program to print the month name for a given number (input 4 → "April").

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter month number (1-12): 4
April
#include <stdio.h>

int main()
{
    int m;
    printf("Enter month number (1-12): ");
    scanf("%d", &m);
🎤 Viva questions (3)
Q. Can switch use a string like "April"?
A. No, C switch works only with integer or char values.
Q. What is fall-through?
A. When a case has no break, the next case also runs.
Q. Why use default?
A. To handle invalid input such as 13.

Practical 13Compulsory

while loop and do...while loop

Aim: Repeat statements with while (entry-controlled) and do...while (exit-controlled) loops.

Q1Program 1: use a while loop.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a number: 4521
Sum of digits = 12
#include <stdio.h>

int main()
{
    int n, sum = 0;
    printf("Enter a number: ");
    scanf("%d", &n);

Q2Program 2: use a do...while loop.

Showing answer A of 3 · tap A, B or C to see the others

Output


1. Square  2. Cube  3. Exit
Choice: 1
Enter number: 6
Square = 36

1. Square  2. Cube  3. Exit
Choice: 2
Enter number: 3
Cube = 27

1. Square  2. Cube  3. Exit
Choice: 3
Bye!
#include <stdio.h>

int main()
{
    int ch, n;
    do {
        printf("\n1. Square  2. Cube  3. Exit\nChoice: ");
        scanf("%d", &ch);
🎤 Viva questions (4)
Q. Difference between while and do...while?
A. while checks first (may run 0 times); do...while checks after (runs at least once).
Q. What is an infinite loop?
A. A loop whose condition never becomes false, e.g. while(1).
Q. Which loop is exit-controlled?
A. do...while.
Q. Why is a semicolon needed after do...while?
A. Because while (condition); ends the do...while statement.

Practical 14

for loop

Aim: Use the for loop where initialization, condition and update are written in one line.

QImplement C programs using a for loop (e.g. print numbers 1 to 100).

Showing answer A of 3 · tap A, B or C to see the others

Output

   1   2   3   4   5   6   7   8   9  10
  11  12  13  14  15  16  17  18  19  20
  21  22  23  24  25  26  27  28  29  30
  31  32  33  34  35  36  37  38  39  40
  41  42  43  44  45  46  47  48  49  50
  51  52  53  54  55  56  57  58  59  60
  61  62  63  64  65  66  67  68  69  70
  71  72  73  74  75  76  77  78  79  80
  81  82  83  84  85  86  87  88  89  90
  91  92  93  94  95  96  97  98  99 100
#include <stdio.h>

int main()
{
    int i;
    for (i = 1; i <= 100; i++) {
        printf("%4d", i);
        if (i % 10 == 0)
🎤 Viva questions (3)
Q. Syntax of for loop?
A. for (initialization; condition; update) { body }
Q. Can we leave parts of for empty?
A. Yes, for(;;) is an infinite loop.
Q. for vs while?
A. for is used when the number of repetitions is known; while when it depends on a condition.

Practical 15Compulsory

Patterns using loops

Aim: Print star and number patterns using nested loops.

QPrint various patterns using loops (star pattern).

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter number of rows: 5
* 
* * 
* * * 
* * * * 
* * * * *
#include <stdio.h>

int main()
{
    int rows, i, j;
    printf("Enter number of rows: ");
    scanf("%d", &rows);
🎤 Viva questions (3)
Q. What is a nested loop?
A. A loop inside another loop.
Q. In a pattern, what does the outer loop control?
A. The number of rows.
Q. How many stars in row i of a pyramid?
A. 2 × i − 1.

Practical 16Compulsory

One-dimensional array

Aim: Store many values of the same type in a 1-D array and process them with a loop.

QImplement C programs using a one-dimensional array (e.g. input 5 numbers, display the sum).

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter 5 numbers: 12 7 25 9 14
Numbers: 12 7 25 9 14 
Sum = 67, Average = 13.40
#include <stdio.h>

int main()
{
    int a[5], i, sum = 0;
    printf("Enter 5 numbers: ");
    for (i = 0; i < 5; i++) {
        scanf("%d", &a[i]);
🎤 Viva questions (4)
Q. What is an array?
A. A collection of elements of the same data type stored in continuous memory.
Q. What is the index of the first element?
A. 0.
Q. How to find the number of elements?
A. sizeof(array) / sizeof(array[0]).
Q. What happens if we access a[10] in int a[5]?
A. Out of bounds — undefined behaviour; C does not check it.

Practical 17Compulsory

Two-dimensional array

Aim: Store a table (matrix) in a 2-D array and perform matrix operations.

QImplement C programs using a two-dimensional array (e.g. addition of two 3×3 matrices).

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter matrix A (9 numbers):
1 2 3 4 5 6 7 8 9
Enter matrix B (9 numbers):
9 8 7 6 5 4 3 2 1
A + B =
  10  10  10
  10  10  10
  10  10  10
#include <stdio.h>

int main()
{
    int a[3][3], b[3][3], c[3][3], i, j;
    printf("Enter matrix A (9 numbers):\n");
    for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) scanf("%d", &a[i][j]);
    printf("Enter matrix B (9 numbers):\n");
🎤 Viva questions (3)
Q. How is a 2-D array stored in memory?
A. Row by row (row-major order) in continuous memory.
Q. Condition for multiplying matrices?
A. Columns of the first must equal rows of the second.
Q. How to declare a 2-D array?
A. type name[rows][columns]; e.g. int a[3][3];

Practical 18Compulsory

String length and reverse without library functions

Aim: Work with strings as character arrays ending with \0, without using strlen() or strrev().

Q1i) Find the length of a string without strlen().

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a word: Polytechnic
Length of "Polytechnic" = 11
#include <stdio.h>

int main()
{
    char s[100];
    int len = 0;
    printf("Enter a word: ");
    scanf("%99s", s);

Q2ii) Reverse a string without strrev().

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a word: Computer
Reverse: retupmoC
#include <stdio.h>

int main()
{
    char s[100];
    int len = 0, i;
    printf("Enter a word: ");
    scanf("%99s", s);
🎤 Viva questions (4)
Q. What is the null character?
A. '\0' — it marks the end of a string.
Q. Size needed for "HELLO"?
A. 6 bytes: 5 letters + 1 for \0.
Q. Why use %[^\n] in scanf?
A. To read a string that contains spaces.
Q. Name standard string functions.
A. strlen, strcpy, strcat, strcmp (and strrev in some compilers).

Practical 19

Structure in C

Aim: Group related data of different types under one name using struct.

QImplement a structure in C (e.g. add and subtract complex numbers using a structure).

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter first complex number (real imag): 3.5 2
Enter second complex number (real imag): 1.5 4
Sum        = 5.0 + 6.0i
Difference = 2.0 - 2.0i
#include <stdio.h>

struct complex {
    float real;
    float imag;
};

int main()
🎤 Viva questions (4)
Q. What is a structure?
A. A user-defined data type that groups variables of different types.
Q. How to access a member?
A. With the dot operator: variable.member (arrow -> with a pointer).
Q. Structure vs array?
A. An array stores the same type; a structure can store different types.
Q. Keyword to define a structure?
A. struct.

Practical 20Compulsory

Array of structure

Aim: Store records of many people using an array of structures.

QImplement an array of structure (e.g. accept and display information of 10 employees).

Showing answer A of 3 · tap A, B or C to see the others

Output

How many employees (max 10)? 3
Employee 1 - id name salary: 101 Ravi 25000
Employee 2 - id name salary: 102 Meena 31000
Employee 3 - id name salary: 103 Arjun 28500

ID    Name             Salary
101   Ravi           25000.00
102   Meena          31000.00
103   Arjun          28500.00
#include <stdio.h>

struct employee {
    int id;
    char name[20];
    float salary;
};
🎤 Viva questions (3)
Q. What is an array of structure?
A. An array whose every element is a structure variable.
Q. How to access the name of the 3rd employee?
A. e[2].name
Q. Can we assign one structure to another?
A. Yes, if both are of the same structure type.

Practical 21Compulsory

Built-in mathematical and string functions

Aim: Use library functions from math.h and string.h.

Q1Program 1: use built-in mathematical functions.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a number: 20.25
sqrt(20.25)  = 4.5000
pow(20.25,3) = 8303.77
ceil(20.25)  = 21
floor(20.25) = 20
abs(-20)     = 20
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
    double x;
    printf("Enter a number: ");

Q2Program 2: use built-in string functions.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter two words: Ananda Tech
Length of Ananda = 6
Joined   = AnandaTech
Words are different (strcmp = -1)
#include <stdio.h>
#include <string.h>

int main()
{
    char a[50], b[50], c[100];
    printf("Enter two words: ");
    scanf("%49s %49s", a, b);
🎤 Viva questions (4)
Q. Header file for sqrt()?
A. math.h (link with -lm on Linux).
Q. Difference between strcpy and strcat?
A. strcpy copies a string; strcat appends to the end of another.
Q. What does strcmp return for equal strings?
A. 0.
Q. ceil(4.2) and floor(4.8)?
A. ceil(4.2) = 5, floor(4.8) = 4.

Practical 22Compulsory

User-defined functions

Aim: Divide a program into functions with declaration, definition, call and return value.

QWrite a C program to demonstrate user-defined functions.

Showing answer A of 3 · tap A, B or C to see the others

Output

Welcome to functions!
Enter a number: 6
Enter a number: 9
Square of 6 = 36
Sum = 15
#include <stdio.h>

void greet(void);                 /* no argument, no return */
void square(int n);               /* argument, no return    */
int  readNumber(void);            /* no argument, return    */
int  add(int a, int b);           /* argument and return    */

int main()
🎤 Viva questions (4)
Q. What is a function prototype?
A. A declaration that gives the function name, return type and parameter types.
Q. Actual vs formal parameters?
A. Actual parameters are passed in the call; formal parameters receive them in the definition.
Q. What is call by value?
A. A copy of the value is passed, so changes inside the function do not affect the original.
Q. Can a function return more than one value?
A. Not directly; use pointers or a structure.

Practical 23

Recursive functions

Aim: Write functions that call themselves, with a base case to stop.

QImplement recursive functions in a C program.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter a number: 6
6! = 720
#include <stdio.h>

long fact(int n)
{
    if (n <= 1)               /* base case */
        return 1;
    return n * fact(n - 1);   /* recursive call */
}
🎤 Viva questions (4)
Q. What is recursion?
A. A function calling itself.
Q. What is a base case?
A. The condition at which recursion stops.
Q. What happens without a base case?
A. Infinite calls until the stack overflows.
Q. Recursion vs loop?
A. Recursion is shorter for some problems but uses more memory (stack).

Practical 24Compulsory

Address and value of variables using pointers

Aim: Store the address of a variable in a pointer and read the value through it.

QPrint the addresses and values of variables using pointers.

Showing answer A of 3 · tap A, B or C to see the others

Output

Value of a = 25,   address = 0x7fff16f85108
Value of b = 4.75, address = 0x7fff16f8510c
Value of c = K,    address = 0x7fff16f85107
Size of a pointer = 8 bytes
#include <stdio.h>

int main()
{
    int a = 25;      float b = 4.75f;    char c = 'K';
    int *pa = &a;    float *pb = &b;     char *pc = &c;

    printf("Value of a = %d,   address = %p\n", *pa, (void *)pa);
🎤 Viva questions (4)
Q. What is a pointer?
A. A variable that stores the address of another variable.
Q. Meaning of & and *?
A. & gives the address; * gives the value at an address.
Q. What is a NULL pointer?
A. A pointer that points to nothing (value NULL).
Q. Size of a pointer on a 64-bit system?
A. 8 bytes, whatever the data type.

Practical 25Compulsory

Arithmetic operations using pointers

Aim: Perform arithmetic on values through pointers and move pointers over an array.

QImplement C programs to perform arithmetic operations using pointers.

Showing answer A of 3 · tap A, B or C to see the others

Output

Enter two numbers: 15 4
Sum        = 19.00
Difference = 11.00
Product    = 60.00
Division   = 3.75
#include <stdio.h>

int main()
{
    float a, b;
    float *p = &a, *q = &b;
    printf("Enter two numbers: ");
    scanf("%f %f", p, q);
🎤 Viva questions (4)
Q. Which arithmetic is allowed on pointers?
A. Add or subtract an integer, subtract two pointers of the same array, compare them.
Q. If int *p holds 1000, what is p + 1?
A. 1004 (int is 4 bytes).
Q. Can two pointers be added?
A. No, adding two addresses has no meaning.
Q. Relation between array and pointer?
A. a[i] is the same as *(a + i).

Tick the answers you want in your file