Programming in c
Programming in c
3) Bitwise Operators:
Operator
&,
`
^
~
<<
>>
Logical Operators:
Ex: &&, !.
++a (Pre-increment):
a++ (Post-increment):
5) Define Array
the same data type in contiguous memory locations.
6)what is getchar()
8)Define Searching
The * (asterisk)
Array: A collection of elements of the same type stored in contiguous memory locations.
Pointer: A variable that stores the memory address of another variable (including an array).
PART B
11. A Explain about the various decision making statements in “C” language.
if Statement
if-else Statement
Nested if Statement
switch Statement
11. B (i) Discuss about the various data types in “C”.
a) Integer (int)
c) Character (char)
Arithmetic Operators
Logical Operators
Bitwise Operators
Assignment Operators
1. For Loop
2. While Loop
3. Do-While Loop
12. B Write a C program to find the sum of 10 non-negative numbers entered by the user.
#include <stdio.h>
int main() {
int numbers[10];
int sum = 0;
do {
if (numbers[i] < 0) {
sum += numbers[i];
return 0;
One-Dimensional Array
Memory Representation
Two-Dimensional Array
A two-dimensional array is an array of arrays, meaning it stores elements in a matrix format (rows and
columns).
Binary Search is an efficient searching algorithm that finds an element in a sorted array by
repeatedly dividing the search range in half. It follows the divide and conquer approach.
Selection Sort in C
Selection Sort is a simple and efficient sorting algorithm that repeatedly selects the smallest
element from the unsorted part of the array and swaps it with the first unsorted element.
Linear Search in C
Linear Search is a simple searching algorithm used to find the position of a target element in a
list or array.
If the element is not found, return -1 indicating the element is not present in the array.
14. B Explain in detail about String Operations
1. String Creation
Call by Reference
Call by Reference is a method of passing arguments to a function where the actual memory
address of the variable is passed. In Call by Reference, the function operates on the actual data,
rather than a copy, making it efficient for large data structures.
Key Points:
Memory Efficiency: No extra memory is used since no copies are made.
Faster Execution: Since original variables are modified directly.
Use Cases: Useful when dealing with large data structures like arrays or objects.
15. B Can you subtract pointers from each other? Why would you?
Finding the index difference – Subtracting two pointers that point to elements of the same
array gives the number of elements between them.
Iterating over an array efficiently – This is useful in pointer arithmetic, especially for
determining how far one pointer is from another.
Checking the range of pointers – Ensures that a pointer stays within the bounds of an array.
#include <stdio.h>
#define SIZE 3
resultMatrix[i][j] = 0;
printf("%d\t", matrix[i][j]);
printf("\n");
}
}
int main() {
scanf("%d", &firstMatrix[i][j]);
scanf("%d", &secondMatrix[i][j]);
displayMatrix(resultMatrix);
return 0;
#include <stdio.h>
if (n == 0 || n == 1) {
return 1;
}int main() {
int num;
scanf("%d", &num);
if (num < 0) {
} else {
return 0;