C Programming 2 Mark Questions with Answer
2 Marks (IMP)
1. Write any two differences between compiler & interpreter.
2. Mention logical & relational operators.
- Relational operators :
==: equal to
!=: not equal to
<: less than
<=: less than or equal to
>: greater than
>=: greater than or equal to - Logical operators :
&&: and
||: or
!: not
3. State the syntax of if-else statement.
if (condition) {
// code to execute if the condition is true
} else {
// code to execute if the condition is false
}
4. Write the syntax of do-while loop.
do {
// code to execute
} while (condition);
5. What are arrays? How arrays are declared?
An array is a data structure that stores a collection of elements of the same data type. Arrays are useful for storing and managing data in a sequential order.
The syntax :
data_type array_name[size];
6. What is goto statement? Why it is not recommended to use?
The goto statement is a flow control statement that allows you to transfer the execution of a program to any other labeled statement in the program.
The goto statement is not recommended to use because it can make code difficult to read, maintain, and debug. When you use the goto statement, it can be difficult to track the flow of the program and understand how it works.
7. What is local variable & global variable?
A local variable is a variable that is declared inside a function or a block of code. Local variables can only be accessed by the function or block of code in which they are declared.
A global variable is a variable that is declared outside of all functions and blocks of code. Global variables can be accessed from anywhere in the program.
8. What is function? List types of functions.
A function is a block of code that performs a specific task.
Functions are used to organize and reuse code, and to make code more modular and easier to maintain.
There are two main types of functions:
Built-in functions
User-defined functions
9. What is gets()? give the syntax.
The gets() function is a C library function that reads a line of input from the standard input stream (stdin) and stores it in a string.
The syntax :
char *gets(char *str);
10. What is symbolic constant?
A symbolic constant is a constant value that is represented by a name. Symbolic constants are used to make code more readable and maintainable, and to avoid repeating the same constant values throughout the code.
11. List different format specifiers
Here is a list of common format specifiers:
%d: Integer format
%f: Floating-point format
%s: String format
%c: Character format
%%: Percent sign format
12. Mention string functions in C.
most common string functions in C:
- strlen()
- strcpy()
- strcat()
- strcmp()
- strchr()
- strstr()
13. State syntax of if else.
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
14. What is string? How to declare it?
A string is a sequence of characters. In C, a string is represented as a character array that ends with the null character (‘\0’). The null character is a special character that indicates the end of the string.
To declare a string syntax:
char string_name[size];
15. What is a union? How to define it?
A union is a user-defined data type in C that allows you to store different data types in the same memory location. This can be useful for saving memory or for creating a data type that can be used for multiple purposes.
Syntax :
union union_name {
member_type1 member_name1;
member_type2 member_name2;
…
member_typeN member_nameN;
};
16. List the different types of constants used in c.
- Primary constants
- Integer constants
- Floating-point constant
- Character constants
- String constants
17. What is comma operator used in C?
The comma operator in C is a binary operator that evaluates its operands from left to right and returns the value of the rightmost operand. The comma operator has the lowest precedence of all C operators.
18. Which are the different data types available in C?
Primary data types: These are the basic data types that are supported by the C language. They include:
- Integer types: These can be signed or unsigned, and they can be short, int, long, or long long.
- Floating-point types: These are float, double, and long double.
- Character types: These are char and unsigned char.
Derived data types: These are data types that are created from the primary data types. They include:
- Arrays: Arrays are collections of elements of the same data type.
- Structures: Structures are collections of elements of different data types.
- Unions: Unions are collections of elements of different data types, but only one element can contain a value at a time.
- Pointers: Pointers are variables that store the address of another variable.
Void type: The void type is used to represent the absence of a value. It is often used as the return type of functions that do not return a value.
19. What are getchar() and putchar() functons?
getchar() reads a single character from the standard input stream (stdin). It returns the character as an integer value. If there is no character available to read, getchar() returns the value EOF.
putchar() writes a single character to the standard output stream (stdout). It takes the character as an integer value as its argument.
20. Who developed C and when?
C was developed by Dennis Ritchie at Bell Labs in the early 1970s.
21. How array are declare in C?
data_type array_name[size];
22. Define function and name the different types of functions.
A function in C is a block of code that performs a specific task. Functions can be used to organize code, make it reusable, and improve the readability of your programs.
There are two main types of functions in C:
- Library functions
- User-defined functions
23. How structure are declare in C?
struct structure_name {
member_type1 member_name1;
member_type2 member_name2;
…
member_typeN member_nameN;
};
24. What is C-programming?
C programming is a general-purpose programming language that is used to develop a wide variety of applications, including operating systems, embedded systems, device drivers, and application software. It is known for its speed, portability, and efficiency.
25. Define term variable and write the syntax of variable declaration.
A variable in C programming is a named storage location that can hold a value. Variables are used to store data that changes during the execution of a program.
The syntax :
data_type variable_name;
26. define looping statements in C?
Looping statements in C are used to repeat a block of code until a certain condition is met. This can be useful for tasks such as iterating over an array, performing a calculation multiple times, or getting input from the user until they provide a valid value.
27. Write a syntax of while-loop statements?
while (condition) {
// block of code to be executed
}
28. List the different types of error occurred during execution.
- Logical Error
- Syntax Error
29. Define the term an array.
An array in C is a data structure that can store a collection of elements of the same data type. Arrays are stored in contiguous memory locations, meaning that the elements of an array are stored next to each other in memory.
30. Define the term structure.
A structure in C is a data type that can be used to store a collection of related data items of different data types. Structures are declared using the struct keyword.
31. Give the syntax of union defination.
union union_name {
member_type1 member_name1;
member_type2 member_name2;
…
member_typeN member_nameN;
};
32. Why and when we use compiler?
Compilers are used to translate high-level programming languages into machine code that can be executed by a computer. This is necessary because computers can only understand machine code, which is a series of binary instructions. Compilers allow programmers to write code in high-level languages, which are easier to read and maintain.
33. Why documentation section is used in a program?
The documentation section in a program is used to provide information about the program, such as its purpose, how to use it, and any known bugs.
34. Write the different methods to decrement the value of a variable.
Prefix decrement: This operator decrements the value of the variable before it is used in an expression. The prefix decrement operator is written as –.
Postfix decrement: This operator decrements the value of the variable after it is used in an expression. The postfix decrement operator is written as –.
35. How do you initialize arrays?
Using an initializer list: An initializer list is a list of values that is enclosed in curly braces ({ }). The initializer list is specified when the array is declared. For example, the following code declares an array of 5 integers and initializes it with the values 1, 2, 3, 4, and 5:
int my_array[5] = {1, 2, 3, 4, 5};
36. Write the syntax of function declaration .
syntax :
return_type function_name(parameter_list);
37. What is programming language ?
A programming language is a formal language that specifies a set of instructions that can be executed by a computer. It is used to create computer software, and it is essential for developing applications, websites, and other types of digital content.
38. Mention the problem solving techniques.
- Divide and conquer
- Greedy algorithms
- Dynamic programming
- Design
- Analyzing
- Implementation
39. What is an assembler?
n assembler is a program that translates assembly language code into machine code. It translate assembly language into low level language.
40. List the primitive data types and format specifiers.
Data type Format specifier
Integer %d or %i
Floating-point %f
Double %lf
Character %c
Boolean %d
41. What are pre-increment and post increment Operators ?
Pre-increment and post-increment operators are two ways to increment the value of a variable by one.
The post-increment operator (++) is placed after the variable name. It increments the value of the variable after it is used in an expression.
42. Write general syntax for do ---while loop statements.
do {
// loop body
} while (condition);
43. What are the advantages of global variables?
- Accessibility
- Reusability
- Configuration
44. What is user defined function?Write syntax..
A user-defined function in C is a function that is created by the programmer, as opposed to a built-in function that is provided by the C compiler. User-defined functions are useful for encapsulating common functionality and making code more reusable and maintainable.
syntax :
return_type function_name(parameter_list) {
// function body
}
45. what is variable in C with example.
A variable in C is a named storage location that can be used to store data. Variables can be declared to store different types of data, such as integers, floating-point numbers, characters, and strings.
int x;
float y;
46. Define compiler and loader.
A compiler is a computer program that translates source code written in a programming language (the source language) into another computer language (the target language). The target language is often a lower-level language, such as machine code or assembly language.
A loader is a computer program that loads executable files into memory and prepares them for execution. The loader performs several tasks.
47.Mention bitwise operator..
- AND (&)
- OR (|)
- XOR (^)
- NOT (~)
- Left shift (<<)
- Right shift (>>)
48. Define UNION in C.
A union in C is a user-defined data type that allows you to store different data types in the same memory location. This can be useful for saving memory or for working with data that needs to be represented in different ways.
49. List any four standard mathematical functions.
- sqrt() – Calculates the square root of a number.
- pow() – Raises a number to a power.
- exp() – Calculates the exponential of a number.
- log() – Calculates the natural logarithm of a number.
50. Difference between break and continue statements.
51. Write the rules for framing variable names.
- Variable names can only contain letters (both uppercase and lowercase letters), digits, and underscores.
- Variable names must start with a letter or an underscore (_).
- Variable names cannot contain spaces or special characters like !, #, %, etc.
- Reserved words (such as int, float, and char) cannot be used as names.
52. What is the role of strrev()?
The strrev() function in C reverses the order of the characters in a string. It is defined in the <string.h> header file.
The strrev() function takes a pointer to a string as its argument and returns a pointer to the reversed string.
Send me BCA 1sem c programming, mathematics, fundamentals computer question paper.Also c programming for bca 1sem notes
Already uploaded please check once.
Very well
Sir Add SEP Nots Also