0% found this document useful (0 votes)
22 views5 pages

CPL Program

Uploaded by

fengneng47
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)
22 views5 pages

CPL Program

Uploaded by

fengneng47
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/ 5

Compiler: A compiler is a Operators: The operators are 3.

Logical Operators: • &&


special program that types of symbols that inform (Logical AND): Returns true if
translates a programming a compiler for performing both operands are true. • ||
language's source code into some specific logical or (Logical OR): Returns true if at
machine code, bytecode or mathematical functions least one operand is true. • !
another programming (Logical NOT): Returns the
1. Arithmetic Operators: • +
language. inverse of the operand's
(Addition): Adds two
logical state.
Datatypes: • int: Used to operands. • - (Subtraction):
represent integer values Subtracts the right operand 4.Assignment Operators: • =
(whole numbers). • char: from the left operand. • * (Assignment): Assigns the
Used to represent a single (Multiplication): Multiplies value of the right operand to
character or a small integer two operands. • / (Division): the left operand. • *+=, -=, =,
value. • float: Used to Divides the left operand by /=, %=: Performs arithmetic
represent floating-point the right operand. • % operation and assigns the
numbers (numbers with a (Modulo): Returns the result to the left operand.
fractional part). • double: remainder of the division of Operators: The operators are
Used to represent double- the left operand by the right types of symbols that inform
precision floating-point operand. a compiler for performing
numbers (more precision some specific logical or
2.Relational Operators: • ==
than float). mathematical functions.
(Equal to): Checks if two
Ternary Operator: when we
Keywords: Keywords are operands are equal. •! = (Not
use an operator on three
predefined, reserved words equal to): Checks if two
variables or operands, it is
used in programming that operands are not equal. • >
known as a Ternary Operator.
have special meanings to the (Greater than): Checks if the
compiler. left operand is greater than Type Casting: Type casting
the right operand. • < (Less refers to changing an variable
Ternary Operator: when we
than): Checks if the left of one data type into another.
use an operator on three
operand is less than the right
variables or operands, it is Difference Between Logical &
operand. • >= (Greater than
known as a Ternary Operator. and Bitwise & in c.
or equal to): Checks if the left
operand is greater than or The logical AND operator
equal to the right operand. • works on Boolean
<= (Less than or equal to): expressions, and returns
Checks if the left operand is Boolean values only. The
less than or equal to the right bitwise AND operator works
operand. on integer, short int, long,
unsigned int type data, and
also returns that type of data.
Modulus: Modulus is a binary Union: Union is a user
arithmetic operator in C defined datatype in C
language, denoted using % programming language. It is a
symbol. Syntax: a % b, it gives collection of variables of
the remainder of, when a is different datatypes in the
divided by b. It is only same memory location.
appliable to integer
operands; using it with float
or double will give compile
time error.

Call By Value: In this


parameter passing method,
values of actual parameters
are copied to function's
formal parameters and the
two types of parameters are
stored in different memory
locations.

Call By reference: Call by strstr(): The strstr() function


reference method copies the returns pointer to the first
address of an argument into occurrence of the matched
the formal parameter. In this string in the given string. It is
method, the address is used used to return substring from
to access the actual argument first match till the last
used in the function call. It character.
means that changes made in Function: Functions in C are
the parameter alter the the basic building blocks of a
passing argument. C program. A function is a set
Structure: Structures (also of statements enclosed
called structs) are a way to within curly brackets ({}) that
group several related take inputs, do the
variables into one place. Each computation, and provide the
variable in the structure is resultant output. You can call
known as a member of the a function multiple times,
structure. Unlike an array, a thereby allowing reusability
structure can contain many and modularity in C
different data types (int, float, programming.
char, etc.).
What are the arguments of
function in C ? The values that
are declared within a function
when the function is called
are known as an argument.
These values are considered
as the root of the function
that needs the arguments
while execution, and it is also
known as Actual arguments
or Actual Parameters.

Pointer: A pointer is a
variable that stores the
memory address of another
variable as its value. A pointer
variable points to a data type
(like int ) of the same type,
and is created with the *
operator.

Command-line arguments:
Command-line arguments are What is the use of # define?
arguments that are indicated The #define creates a macro,
after the name of the which is the association of an
program in the framework's identifier or parameterized
order line, and these identifier with a token string.
arguments are given to your After the macro is defined,
program during program the compiler can substitute
execution. the token string for each
occurrence of the identifier in
the source file.
WAP to sort an array WAP to sum and Avg. of array WAP to check prime no.

#include <stdio.h> #include <stdio.h> #include <stdio.h>

#include <stdlib.h> int main () { #include <stdbool.h>

// Custom comparator int n, i; bool isPrime(int n) {

int comp(const void* a, const void* b) { float sum = 0.0, average; if (n <= 1) return false;

// If a is smaller, positive value will be returned printf("Enter the number of elements: "); for (int i = 2; i <= n / 2; i++) {

return (*(int*)a - *(int*)b); scanf("%d", &n); if (n % i == 0) return false;

} int arr[n]; }

int main() { printf("Enter the elements:\n"); return true;

int arr[] = { 2 ,6, 1, 5, 3, 4 }; for (i = 0; i < n; i++) { }

int n = sizeof(arr) / sizeof(arr[0]); scanf("%d", &arr[i]); int main() {

// Sort the array using qsort sum += arr[i]; int num;

qsort(arr, n, sizeof(int), comp); } printf("Enter a number: ");

for (int i = 0; i < n; i++) average = sum / n; scanf("%d", &num);

printf("%d ", arr[i]); printf("Sum = %.2f\n", sum); if (isPrime(num))

return 0; printf("Average = %.2f\n", average); printf("%d is a prime number.\n", num);

} return 0; else

} printf("%d is not a prime number.\n", num);


WAP to find fibonacci series What’s an array? How to declare an When you pass a structure by reference,
array? with examples a pointer to the structure is passed to
#include <stdio.h> the function. This allows the function to
An array is a data structure that stores a modify the original structure.
void generateFibonacci(int n) { collection of elements of the same data
type in contiguous memory Whats object oriented program?
int t1 = 0, t2 = 1, nextTerm; locations. Think of it as a container with
printf("Fibonacci Series: %d, %d", t1, t2); multiple slots, where each slot can hold Object-oriented programming (OOP) is a
a single value. computer programming model that
for (int i = 3; i <= n; ++i) { organizes software design around
objects, rather than functions and logic
nextTerm = t1 + t2;
The four main features of OOP
printf(", %d", nextTerm);
are encapsulation, inheritance,
t1 = t2; polymorphism, and abstraction.

t2 = nextTerm;

printf("\n");

int main() {

int n;

printf("Enter the number of terms: ");

scanf("%d", &n);
What is header file? How to use it?
if (n < 1) {
A text file that contains definitions and
printf("Please enter a positive structures for C programs, such as
integer.\n"); function definitions, variable
declarations, and macro definitions
} else if (n == 1) {
How to use_Header files are included in
printf("Fibonacci Series: 0\n"); a program using the preprocessing
directive #include.
} else {
Recursion in c programming
generateFibonacci(n);
a technique where a function calls itself
}
directly or indirectly to solve a problem.
return 0; It is a powerful tool for solving problems
that can be broken down into smaller,
} similar subproblems. Recursion is often
used in algorithms for tasks such as
return 0; searching, sorting, and traversing data
structures like trees and graphs.
}
Passing array to function (with
example)

you can pass a structure to a function in


two ways: by value and by reference.

When you pass a structure by value, a


copy of the structure is passed to the
function. Any changes made to the
structure within the function do not
affect the original structure.

You might also like