0% found this document useful (0 votes)
6 views2 pages

Quiz 11

This document contains a quiz for a Programming Fundamentals course focused on pointers and modular programming concepts. It includes a series of questions requiring students to fill in blanks, mark statements as true or false, and write C programs for specific tasks involving pointers and matrix multiplication. The quiz is structured to assess understanding of key programming principles and syntax.

Uploaded by

mabdullah4505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Quiz 11

This document contains a quiz for a Programming Fundamentals course focused on pointers and modular programming concepts. It includes a series of questions requiring students to fill in blanks, mark statements as true or false, and write C programs for specific tasks involving pointers and matrix multiplication. The quiz is structured to assess understanding of key programming principles and syntax.

Uploaded by

mabdullah4505
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CC-112 Programming Fundamentals Spring 2022

Quiz 10 – Lecture 15-16-17 – Pointers – I-II-III [50 Marks, 50 Minutes]


MAbdullah
Name: ______________________________________ 133715
Roll No: _____________________________
Question 1: [1x5 marks] [est. time 5 minutes] 2.
Supply the missing words to complete the statements. #include<stdio.h>
int main ()
1. Referencing through a pointer is called {
_____________.
dereferencing. const int i = 20;
const int* const ptr = &i;
2. The const keyword enables you to inform the
____________ (*ptr)++;
compiler that a particular variable’s value should not int j = 15;
ptr = &j;
be modified. return 0;
3. Three values can be used to initialize a pointer — }
Output: ______________________________________
Compilation Error
__________
NULL,0 and __________.
address
3.
4. A pointer variable contains as its value another
#include <stdio.h>
variable’s ____________.
memory address int main()
{
Question 2: [1x5 marks] [est. time 5 minutes] char* str[] = { "AAAAA", "BBBBB", "CCCCC"};
In the following questions mark True or False. char** sptr[] = { str + 2, str + 1, str };
char*** pp;
a) (T / F) A pointer can be initialized by 0.
pp = sptr;
b) (T / F) Dereferencing a pointer that has not been ++pp;
printf("%s", **pp + 2);
assigned the address of another variable in memory is
return 0;
an error. }
"BBB"
c) (T / F) By default, arrays are passed by value. Output: ______________________________________
d) (T / F) An array name is like a constant pointer. 4.
e) (T / F) If bPtr points to array b’s third element #include<stdio.h>
int main()
(b[2]), then element b[4] also can be referenced with {
the pointer/offset notation expression *(bPtr + 2). int i = 6, *j, k;
j = &i;
Question 3: [4x4 marks] [estimated time 10 minutes] printf("%d\n", i * *j * i + *j);
Dry Run the pseudocode and write the expected return 0;
output. (Write “Blank” for no output or write }
“Compilation Error” if there is any error). 222
Output: ______________________________________
1.
Question 4: [12 marks] [estimated time 15 minutes]
#include<stdio.h>
int main () Write a menu driven C program that:
{  Take radius as an input from the user
int arr[] = { 1, 4, 5, 6, 7 };  Allow the user to choose whether to calculate a
int* p = (arr + 1); circle’s circumference (2*pi*r), a circle’s area(pi*r2 )
printf(“%d”, *arr + 10); or a sphere’s volume (4/3 *pi*r3 )
return 0;  Use array of function pointers
}  Output the message indicating which calculation is
performed
11
Output: ______________________________________

Quiz 09 – Lecture 09-10-11 – Modular Programming – II-III-IV Page 1 of 2


CC-112 Programming Fundamentals Spring 2022

#include <stdio.h>
_____________________________________________ Question 5: [12 marks] [estimated time 15 minutes]
#include <math.h>
Write a C program that:
_____________________________________________
double circumference(double r) { return 2 * M_PI * r; }  Declare two 2x2 matrices, input elements of both
_____________________________________________
double area(double r) { return M_PI * r * r; } matrices from user and multiply the matrices using
volume(double r) { return (4.0 / 3.0) * M_PI * pow(r, 3); } pointers
double_____________________________________________
Input: First matrix: 1122
_____________________________________________
int main() { Second matrix: 1 1 2 2
double radius; Output: 3 3
_____________________________________________
int choice; 6 6
double (*functions[])(double) = { circumference, area, volume
_____________________________________________ };
_____________________________________________
#include <stdio.h>
_____________________________________________
printf("Enter radius: "); _____________________________________________
void multiplyMatrices(int (*A)[2], int (*B)[2], int
scanf("%lf", &radius);
_____________________________________________ (*C)[2]) {
_____________________________________________
for (int i = 0; i < 2; i++) {
printf("Choose an option:\n1. Circumference\n2. Area\n3. Volume\n");
_____________________________________________ _____________________________________________
for (int j = 0; j < 2; j++) {
scanf("%d", &choice); C[i][j] = 0;
_____________________________________________ _____________________________________________
for (int k = 0; k < 2; k++) {
if (choice >= 1 && choice <= 3) {
_____________________________________________ C[i][j] += A[i][k] * B[k][j];
_____________________________________________
printf("Result: %.2f\n", functions[choice - 1](radius)); }
_____________________________________________
} else { _____________________________________________
}
printf("Invalid choice!\n"); }
} _____________________________________________ _____________________________________________
}
_____________________________________________ _____________________________________________
return 0; int main() {
} _____________________________________________ _____________________________________________
int A[2][2], B[2][2], C[2][2];
_____________________________________________ _____________________________________________
printf("Enter elements of first matrix:\n");
_____________________________________________ _____________________________________________
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
_____________________________________________ _____________________________________________
scanf("%d", &A[i][j]);
_____________________________________________ _____________________________________________
printf("Enter elements of second matrix:\n");
_____________________________________________ _____________________________________________
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++)
_____________________________________________ _____________________________________________
scanf("%d", &B[i][j]);
_____________________________________________ _____________________________________________
multiplyMatrices(A, B, C);
_____________________________________________ _____________________________________________
printf("Resultant Matrix:\n");
_____________________________________________ _____________________________________________
for (int i = 0; i < 2; i++) {
_____________________________________________ _____________________________________________
for (int j = 0; j < 2; j++) {
printf("%d ", C[i][j]);
_____________________________________________ _____________________________________________
}
_____________________________________________ _____________________________________________
printf("\n");
}
_____________________________________________ _____________________________________________
return 0;
_____________________________________________ _____________________________________________
}
_____________________________________________ _____________________________________________
_____________________________________________ _____________________________________________
_____________________________________________ _____________________________________________
_____________________________________________ _____________________________________________
_____________________________________________ _____________________________________________
_____________________________________________ _____________________________________________

Quiz 10 – Lecture 12-13-14 – Arrays – I-II-III Page 2 of 2

You might also like