0% found this document useful (0 votes)
10 views7 pages

2marks Paper3

The document contains model question papers focused on programming concepts, including keywords, constants, functions, decision-making statements, and memory allocation. It provides definitions, examples, and differentiations between various programming elements such as structures, unions, and data types. Additionally, it covers user-defined header files and macros, emphasizing their usage in programming.

Uploaded by

samxtrx
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)
10 views7 pages

2marks Paper3

The document contains model question papers focused on programming concepts, including keywords, constants, functions, decision-making statements, and memory allocation. It provides definitions, examples, and differentiations between various programming elements such as structures, unions, and data types. Additionally, it covers user-defined header files and macros, emphasizing their usage in programming.

Uploaded by

samxtrx
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/ 7

Model Question Paper II

1. What are keywords? Give an example.

Keywords are reserved words with predefined meanings in a programming language.

They cannot be used as identifiers.

Example: int, return, for.

2. What are constants? Give an example.

Constants are fixed values that cannot be altered during program execution.

Declared using const keyword or #define.

Example:

const int MAX = 100;


#define PI 3.14

3. What is putchar() function? Give an example.

putchar() is used to write a single character to the output.

It is part of the <stdio.h> library.

Example:

putchar('A'); // Outputs: A

4. What are decision-making statements? Give an example.

Decision-making statements execute code based on conditions.

Types: if, if-else, switch.

Example:

if (x > 0) printf("Positive");
else printf("Negative");

5. Differentiate between break and continue.


break: Exits a loop or switch case immediately.

continue: Skips the current iteration and moves to the next.

Example:

for (int i = 0; i < 5; i++) {


if (i == 2) continue; // Skips 2
printf("%d ", i);
}

6. What is function prototype? Give an example.

A function prototype declares a function before its definition.

Syntax: return_type function_name(parameter_list);

Example:

void add(int, int);

7. What is a string?

A string is an array of characters terminated by a null character (\0).

Stored as char str[] or char *str.

Example:

char name[] = "Sameer";

8. Differentiate between structure and union.

Structure: Allocates separate memory for each member.

Union: Shares memory between all members.

Example:

struct S { int a; float b; };


union U { int a; float b; };

9. What is typedef? Give an example.


typedef defines a new name for an existing data type.

Improves code readability.

Example:

typedef unsigned int uint;


uint num = 10;

10. Write any two advantages of pointers.

1. Allows direct memory access.

2. Facilitates dynamic memory allocation using malloc() or calloc().

3. Enables efficient handling of arrays and strings.

11. What is malloc()? Give an example.

malloc() allocates dynamic memory during runtime.

Syntax: void* malloc(size_t size);

Example:

int *ptr = (int *)malloc(10 * sizeof(int));

12. What is a user-defined header file?

A custom header file created by the programmer.

Contains user-defined functions, macros, or declarations.

Example: #include "myheader.h"

---

Model Question Paper III

1. What are constants? Give an example.


Constants are immutable values during program execution.

Declared using #define or const keyword.

Example:

#define PI 3.14
const int MAX = 100;

2. What is a data type? Give an example.

A data type specifies the type of data a variable can hold.

Common types: int, float, char.

Example:

int num = 10;


float pi = 3.14;

3. What is getchar() function? Give an example.

getchar() reads a single character from the input.

It is part of the <stdio.h> library.

Example:

char c = getchar();

4. Differentiate between actual and formal arguments.

Actual arguments: Passed to a function during the call.

Formal arguments: Declared in the function definition.

Example:

void display(int num) { // Formal argument


printf("%d", num);
}
display(5); // Actual argument
5. What is goto statement?

goto transfers control to a labeled statement in a program.

Syntax:

goto label;
label: statement;

Example:

int x = 10;
if (x > 0) goto positive;
positive: printf("Positive number");

6. What are nested functions?

Functions defined within another function.

Not supported in standard C.

Workaround: Use function pointers or function calls.

7. What is a string?

A sequence of characters terminated by \0.

Stored in a char array or char pointer.

Example:

char name[] = "John";

8. What is a structure in C?

A structure is a user-defined data type that groups related variables of different types.

Syntax:

struct Name {
int id;
char name[20];
};

Example:
struct Name person;

9. What is an enum? Give an example.

An enum is a user-defined data type that assigns names to integer constants.

Example:

enum days { MON, TUE, WED };

10. What is macro?

A macro is a fragment of code defined using #define.

Example:

#define SQUARE(x) ((x) * (x))

11. Differentiate between static and dynamic memory allocation.

Static: Memory is allocated at compile time.

Dynamic: Memory is allocated at runtime.

Example:

Static: int arr[10];

Dynamic: int *arr = (int *)malloc(10 * sizeof(int));

12. What is a user-defined header file?

A custom header file with user-defined functions or macros.

Example: #include "myheader.h"

---

Let me know if you'd like assistance with Section B or anything else!

You might also like