wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Programming

Total questions: 20

Worksheet time: 8mins

Name
Class
Date
1.

What is a pointer in C and how is it declared?

a)

A pointer in C is simply a variable that holds a string.

b)

A pointer in C is declared using the syntax 'type *pointerName;'. For example, 'int *ptr;' declares a pointer to an integer.

c)

A pointer in C is declared with the syntax 'pointerName : type;'.

d)

A pointer in C is declared using 'type &pointerName;'.

2.

Explain the concept of dynamic memory allocation in C.

a)

Dynamic memory allocation in C is done using static arrays.

b)

Dynamic memory allocation in C is managed automatically by the compiler.

c)

Dynamic memory allocation in C is the process of allocating memory at runtime using functions like malloc and free, allowing for flexible memory management.

d)

Memory allocation in C is only possible at compile time.

3.

Explain how to pass a pointer to a function in C.

a)

You must declare the function without any parameters.

b)

You declare the function with a pointer parameter and pass the address of the variable.

c)

Pointers cannot be used as function parameters in C.

d)

You can only pass variables by value in C.

4.

How can you check if a file has been opened successfully in C?

a)

Check if the file size is greater than zero.

b)

Verify the file extension matches the expected type.

c)

Ensure the file is located in the correct directory.

d)

Check if the file pointer is NULL after fopen().

5.

Find error/ output in following code

How many times " placement Questions" will print.

int main

{

int x;

for ( x=1;x <=10; x++)

{

if ( x < 5)

Continue;

else

break;

Printf (" placement Question ");

{

return 0;

}

a)

Infinite time

b)

11 times

c)

0 time

d)

10 times

6.

Find error/ output in following code

int main ()

{

Static int num = 8;

printf ( " %d" , num = num -2 );

if (num != 0)

main ();

}

a)

8 6 4 2

b)

4 6 8 0

c)

2 4 6 0

d)

6 4 2 0

7.

Find the output in following code

int main ()

{

int a,b ;

a= b= 4 ;

b =a++;

Printf ( " %d %d %d %d", a++, --b, ++a, b--);

}

a)

5 3 73

b)

5 4 5 3

c)

6 2 6 4

d)

6 3 7 4

8.

What is the Priority among (*, /, %), (+, -) and (=) C Operators.?

a)

(*, /, %) >  (+, -) < (=)

b)

(*, /, %) <  (+, -) < (=)

c)

(*, /, %) >  (+, -) > (=)

d)

(*, /, %) <  (+, -)

9.

Who invented C programming language ?

a)

Thompson Ritchie

b)

Dennis Gosling

c)

Dennis Ritchie

d)

James Thompson

10.

How many number of pointer (*) does C have against a pointer variable declaration?

a)

1

b)

2

c)

3

d)

None of these

11.
  1. #include <stdio.h>

  2. union Sti

  3. {

  4. int nu;

  5. char m;

  6. };

  7. int main()

  8. {

  9. union Sti s;

  10. printf("%d", sizeof(s));

  11. return 0;

  12. }

a)

12

b)

8

c)

4

d)

0

12.

#include <stdio.h>

num birds {SPARROW, PEACOCK, PARROT};

num animals {TIGER = 10, LION =15, RABBIT=11, ZEBRA=12};

int main()

{

num birds m = TIGER;

int k;

k = m;

printf("%d\n", k);

return 0;

}

a)

10

b)

11

c)

12

d)

15

13.

#include <stdio.h>

int main()

{

int a = 1, b = 2, c = 3;

if (a > b && a > c)

printf("%d", a);

else if (b > a && b > c)

printf("%d", b);

else

printf("%d", c);

return 0;

}

a)

0

b)

1

c)

2

d)

3

14.

#include <math.h>

int main()

{

double principal = 2300;

double rate = 7;

double time = 4;

double amount

= principal * ((pow((1 + rate / 100), time)));

double CI = amount - principal;

printf("Compound Interest is : %lf", CI);

return 0;

}

a)

712.456

b)

713.598

c)

714.830

d)

715.563

15.

#include <math.h>

#include <stdio.h>

int main()

{

int N = 102301;

int ans = 0;

int i = 0;

while (N != 0) {

if (N % 10 == 0)

ans = ans + 1 * pow(10, i);

else

ans = ans + (N % 10) * pow(10, i);

N = N / 10;

i++;

}

printf("%d", ans);

return 0;

}

a)

112310

b)

112311

c)

112334

d)

112312

16.

#include <stdio.h>

int main()

{

int arr[5] = { 15, 25, 35, 45, 55 };

printf("Element at arr[2]: %d\n", arr[2]);

printf("Element at arr[4]: %d\n", arr[4]);

printf("Element at arr[0]: %d", arr[0]);

return 0;

}

a)

Element at arr[1]: 45

Element at arr[2]: 25

Element at arr[0]: 15

b)

Element at arr[2]: 33

Element at arr[3]: 55

Element at arr[0]: 45

c)

Element at arr[2]: 35

Element at arr[3]: 55

Element at arr[1]: 15

d)

Element at arr[2]: 35

Element at arr[4]: 55

Element at arr[0]: 15

17.

#include <stdio.h>

#include <string.h>

struct student {

char name[20];

int roll_no;

char address[50];

char branch[50];

};

int main()

{

struct student obj;

strcpy(obj.name, "sridharan ");

obj.roll_no = 29;

strcpy(obj.address, " kesari puram ");

strcpy(obj.branch, "Computer Science And Engineering");

printf("Name: %s\n", obj.name);

printf("Roll_No: %d \n", obj.roll_no);

printf("Address: %s\n", obj.address);

printf("Branch: %s", obj.branch);

return 0;

}

a)

name: sridharan

Roll_No: 29

Address: kesari puram

b)

Name: sridharan

Roll_No: 29

address: kesaripuram

c)

Name: sridharan

roll_No: 29

Addres: kesari puram

d)

Name: sridharan

Roll_No: 29

Address: kesari puram

18.

Input/output function prototypes and macros are defined in which header file?

a)

conio.h

b)

stdlib.h

c)

stdio.h

d)

dos.h

19.

Output :

a)
36 63
b)

37 53

c)

38 64

d)

34 56

20.

What will be the address of the arr[2][3] if arr is a 2-D long array of 4 rows and 5 columns and starting address of the array is 2000?

a)

2002

b)

2035

c)

2047

d)

2052