0% found this document useful (0 votes)
17 views

Assignment no 1

Uploaded by

mohsinsherazi63
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Assignment no 1

Uploaded by

mohsinsherazi63
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Q1: Explain 32 available keywords in c language with their

usage?

Here are the 32 keywords in C with their usage explained briefly:


auto: Defines automatic variables with local scope.
break: Exits from loops or switch statements.
case: Marks a branch in a switch statement.
char: Declares character data type variables.
const: Declares constants.
continue:
Skips the current iteration of a loop.
default:
Specifies the default case in a switch statement.
do:
Starts a do-while loop.
double:
Declares double-precision floating-point variables.
else:
Executes a block of code if the if condition is false.
enum:
Declares an enumeration type.
extern:
Declares a variable or function defined in another source file.
float:
Declares single-precision floating-point variables.
for:
Starts a for loop.
goto: Transfers control to another part of the program.
if:
Executes a block of code based on a condition.
int:
Declares integer variables.
long:
Declares long integer variables.
register:
Suggests storing a variable in a CPU register for faster access.
return:
Returns a value from a function.
short:
Declares short integer variables.
signed:
Declares signed integer variables.
sizeof:
Returns the size of a variable or data type in bytes.
static:
Declares static variables with local scope or static functions with global scope.
struct:
Declares a structure type.
switch:
Starts a switch statement.
typedef:
Creates a new data type alias.
union:
Declares a union type.
unsigned:
Declares unsigned integer variables.
void:
Specifies that a function does not return a value or that a pointer does not have a
specific data type.
volatile:
Specifies that a variable can be changed unexpectedly.
while:
Starts a while loop.

Q2: Explain commonly use of built-in function


in C program? Write a program and use all
the built-in function in C language.
Sure, built-in functions in C are functions that are provided by the C standard
library and can be directly used in your C programs without needing to define
them yourself. These functions serve various purposes, such as performing
mathematical operations, manipulating strings, input/output operations, memory
allocation, and more.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main() {
double x = 4.5;
double squareRoot = sqrt(x);
printf("Square root of %.2f is %.2f\n", x, squareRoot);
double y = 3.0;
double powerResult = pow(x, y);

printf("%.2f raised to the power of %.2f is %.2f\n", x, y, powerResult);

char str1[] = "Hello";


char str2[] = "World";
char combinedStr[20];
strcpy(combinedStr, str1);
strcat(combinedStr, " ");
strcat(combinedStr, str2);
printf("Combined string: %s\n", combinedStr);
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("You entered: %d\n", num);
int *arr = (int *)malloc(5 * sizeof(int));
if (arr == NULL) {
printf("Memory allocation failed\n");
return 1;
}
for (int i = 0; i < 5; i++) {

arr[i] = i + 1;
}
printf("Array elements: ");
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);

}
printf("\n");
free(arr);
return 0;
}
This program demonstrates the use of several built-in functions:
Mathematical functions: sqrt() (square root), pow() (power).
String manipulation functions: strcpy() (copy string), strcat() (concatenate strings).
Input/output functions: printf() (formatted output), scanf() (formatted input).
Memory allocation functions: malloc() (allocate memory), free() (free allocated
memory).

You might also like