UNIT-IV
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 1
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 2
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 3
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 4
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 5
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 6
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 7
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 8
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 9
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 10
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 11
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 12
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 13
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 14
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 15
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 16
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 17
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 18
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 19
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 20
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 21
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 22
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 23
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 24
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 25
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 26
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 27
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 28
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 29
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 30
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 31
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 32
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 33
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 34
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 35
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 36
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 37
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 38
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 39
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 40
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 41
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 42
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 43
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 44
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 45
Programming Using C
#include <stdio.h>
int main () {
int var; Value of var = 3000
int *ptr; Value available at *ptr = 3000
Value available at **pptr = 3000
int **pptr;
var = 3000;
/* take the address of var */
ptr = &var;
/* take the address of ptr using address of operator & */
pptr = &ptr;
/* take the value using pptr */
printf("Value of var = %d\n", var );
printf("Value available at *ptr = %d\n", *ptr );
printf("Value available at **pptr = %d\n", **pptr);
return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 46
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 47
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 48
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 49
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 50
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 51
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 52
Programming Using C
• The “malloc” or “memory allocation” method in C is used to dynamically
allocate a single large block of memory with the specified size.
• It returns a pointer of type void which can be cast into a pointer of any
form.
• It doesn’t Initialize memory at execution time so that it has initialized
each block with the default garbage value initially.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 53
Programming Using C
else {
printf("Memory successfully
#include <stdio.h> allocated using malloc.\n");
#include <stdlib.h> for (i = 0; i < n; ++i) {
int main() ptr[i] = i + 1;
{ }
int* ptr; if (ptr == NULL) {
int n, i; printf("Memory not allocated.\n");
printf("Enter number of elements:"); exit(0);
scanf("%d",&n); }
printf("Entered number of printf("The elements of the array are: ");
elements: %d\n", n); for (i = 0; i < n; ++i) {
ptr = (int*)malloc(n * sizeof(int)); printf("%d, ", ptr[i]);
if (ptr == NULL) { }
}
printf("Memory not allocated.\n");
return 0;
exit(0);
}
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 54
Programming Using C
Output:
Enter number of elements: 5
Memory successfully allocated using malloc.
The elements of the array are: 1, 2, 3, 4, 5,
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 55
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 56
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 57
Programming Using C
• “calloc” or “contiguous allocation” method in C is used to
dynamically allocate the specified number of blocks of memory of
the specified type. it is very much similar to malloc() but has two
different points and these are:
• It initializes each block with a default value ‘0’.
• It has two parameters or arguments as compare to malloc()
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 58
Programming Using C
#include <stdio.h>
#include <stdlib.h> printf("Memory successfully
allocated using calloc.\n");
int main()
{
int* ptr; for (i = 0; i < n; ++i) {
int n, i; ptr[i] = i + 1;
n = 5; }
printf("The elements of the array
printf("Enter number of elements: %d\n", n);
are: ");
ptr = (int*)calloc(n, sizeof(int)); for (i = 0; i < n; ++i) {
if (ptr == NULL) { printf("%d, ", ptr[i]);
printf("Memory not allocated.\n"); }
exit(0); }
} return 0;
else { }
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 59
Programming Using C
Output:
Enter number of elements: 5
Memory successfully allocated using calloc.
The elements of the array are: 1, 2, 3, 4, 5,
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 60
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 61
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 62
Programming Using C
• “realloc” or “re-allocation” method in C is used to dynamically change the
memory allocation of a previously allocated memory.
• In other words, if the memory previously allocated with the help of malloc or
calloc is insufficient, realloc can be used to dynamically re-allocate memory.
• re-allocation of memory maintains the already present value and new blocks
will be initialized with the default garbage value.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 63
Programming Using C
#include <stdio.h> else {
printf("Memory successfully allocated using
#include <stdlib.h>
calloc.\n");
int main() for (i = 0; i < n; ++i) {
{ ptr[i] = i + 1;
int* ptr; }
int n, i; printf("The elements of the array are: ");
for (i = 0; i < n; ++i) {
n = 5;
printf("%d, ", ptr[i]);
printf("Enter number of elements: }
%d\n", n); n = 10;
ptr = (int*)calloc(n, sizeof(int)); printf("\n\nEnter the new size of the array:
if (ptr == NULL) { %d\n", n);
printf("Memory not allocated.\n"); ptr = realloc(ptr, n * sizeof(int));
printf("Memory successfully re-allocated using
exit(0); realloc.\n");
} for (i = 5; i < n; ++i) {
ptr[i] = i + 1;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 64
Programming Using C
printf("The elements of the array are: ");
for (i = 0; i < n; ++i) {
printf("%d, ", ptr[i]);
}
free(ptr);
}
return 0;
}
Output:
Enter number of elements: 5
Memory successfully allocated using calloc.
The elements of the array are: 1, 2, 3, 4, 5,
Enter the new size of the array: 10
Memory successfully re-allocated using realloc.
The elements of the array are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 65
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 66
Programming Using C
• “free” method in C is used to dynamically de-allocate the memory.
• The memory allocated using functions malloc() and calloc() is not
de-allocated on their own.
• Hence the free() method is used, whenever the dynamic memory
allocation takes place. It helps to reduce wastage of memory by freeing it.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 67
Programming Using C
#include <stdio.h>
if (ptr == NULL || ptr1 == NULL) {
#include <stdlib.h> printf("Memory not allocated.\n");
exit(0);
int main()
}
{ else {
int *ptr, *ptr1; printf("Memory successfully allocated using
malloc.\n");
int n, i; free(ptr);
n = 5; printf("Malloc Memory successfully freed.\n");
printf("\nMemory successfully allocated using
printf("Enter number of elements: calloc.\n");
%d\n", n); free(ptr1);
printf("Calloc Memory successfully freed.\n");
ptr = (int*)malloc(n * sizeof(int)); }
ptr1 = (int*)calloc(n, sizeof(int)); return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 68
Programming Using C
Output:
Enter number of elements: 5
Memory successfully allocated using malloc.
Malloc Memory successfully freed.
Memory successfully allocated using calloc.
Calloc Memory successfully freed.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 69
Programming Using C
Dangling Pointer
• The pointers pointing to a deallocated memory block are known as
Dangling Pointers. This condition generates an error known as Dangling
Pointer Problem.
• Dangling Pointer occurs when a pointer pointing to a variable goes out of
scope or when an object/variable's memory gets deallocated.
• There are ways to avoid Dangling Pointer Problems like
assigning NULL to the pointer when the memory gets deallocated or
by using static variables.
In this diagram, see three-pointers and observe that Pointer 3 is a dangling
pointer. Pointer 1 and Pointer 2 are the pointers that point to the allocated
objects, i.e., Object 1 and Object 2, respectively whereas Pointer 3 is a
dangling pointer as it points to a deleted object.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 71
Programming Using C
How does Dangling Pointer in C work?
Dangling Pointers are generated when we do not modify the value of
a pointer after the deallocation of a memory block or when a variable
goes out of scope.
The memory occupied by an integer variable is deallocated,
and the pointer pointing to the deallocated memory acts as a
Dangling Pointer (hanging freely).
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 73
Programming Using C
Different ways where pointers act as Dangling
Pointers in C
[Link] of memory
[Link] Call
[Link] goes out of scope
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 74
Programming Using C
Creating Dangling Pointer by De-Allocating the Memory
Deallocating a memory that is pointed by a pointer causes a dangling
pointer. In the below example, we have created an integer pointer.
Then we call the free function by passing the pointer. Once we call
the free function, then the pointer ptr becomes a dangling pointer.
#include <stdlib.h>
#include <stdio.h>
int main()
{
int *ptr = (int *)malloc(sizeof(int));
free(ptr);
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 75
Programming Using C
Avoiding Dangling Pointer Errors in C Language
The dangling pointer errors can be avoided by initializing the pointer to a NULL value.
If we assign the NULL value to the pointer, then the pointer will not point to the de-allocated
memory instead the pointer is not pointing to any memory location.
So, in the below example, after calling the free function, we initialize the pointer with a NULL
value and hence it is not a Dangling Pointer anymore.
#include <stdlib.h>
#include <stdio.h>
int main()
{
int *ptr = (int *)malloc(sizeof(int));
free(ptr);
ptr = NULL;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 76
Programming Using C
Creating Dangling Pointer by Function Call
The pointer pointing to the local variable becomes dangling when the local variable is not static.
In the below example, the variable x is a local variable and goes out of scope once the execution
of the fun() function is completed. And inside the main method, the pointer p is pointing to
something which does not exist anymore and hence the pointer ptr becomes a dangling
pointer.
#include<stdio.h>
int *fun()
{
int x = 5;
return &x;
}
int main()
{
int *ptr = fun ();
printf ("%d", *ptr);
return 0;
}
Output: A garbage Address
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 77
Programming Using C
• Here ptr is called a Dangling Pointer because according to the
storage class of C, by default any type of variable storage class
specifier is auto, and the lifetime of the auto variable is within the
body only.
• The solution of the dangling pointer is in place of creating an auto
variable, create a static variable because the lifetime of the static
variable is the entire program.
• Modify the program as follows where we make the variable x static.
Once we make variable x static, now the variable x has scope
throughout the program.
• So, that the pointer pointing to the local variable doesn’t become a
dangling pointer when the local variable is static.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 78
Programming Using C
#include<stdio.h>
int *fun()
{
static int x = 5;
return &x;
}
int main()
{
int *ptr = fun ();
printf ("%d", *ptr);
return 0;
}
Output: 5
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 79
Programming Using C
Creating Dangling Pointer by Variable goes out of scope
When the variable goes out of scope, then the pointer becomes a
dangling pointer. In this example, first, created one pointer ptr. Then
with the variable scope, initialized the pointer. Once the variable goes
out of scope, then it becomes a dangling pointer.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 80
Programming Using C
#include<stdio.h>
void main()
{
int *ptr;
//Variable scope started
{
int ch;
ptr = &ch;
}
//Variable scope ended
// Now ptr is dangling pointer
printf ("%d", *ptr);
return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 81
Programming Using C
Command Line Arguments
Input values in C code are executed during compile time and runtime. To do that,
declared variables in the main() and then worked on them but there is a way to
input values without declaring them in the main().
C offers us a feature called "command line argument" using which we can enter
values from the command line at the time of execution. A command line
argument is a parameter supplied to the program when it is invoked or run.
Use of Command Line arguments in C:
• They are used when we need to control our program from outside instead of
hard-coding it.
• They make installation of programs easier.
• Command line argument is an important concept in C programming.
• Command line arguments are passed to the main() method.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 82
Programming Using C
Syntax
int main(int argc, char *argv[])
Here,
• argc counts the number of arguments on the command line
and
• argv[ ] is a pointer array that holds pointers of type char
which points to the arguments passed to the program.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 83
Programming Using C
Example to check whether any command line arguments are provided to the
code or not.
#include<stdio.h>
int main(int argc, char *argv[])
{
if(argc < 2)
printf("No argument supplied. The only argument here is %s", argv[0]);
return 0;
}
Compile the above code using: gcc filename.c -o filename
Then run it using: ./filename (or) Just use online C compiler
Output:
No argument supplied. The only argument here is ./[Link]
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 84
Programming Using C
If we want to print all the arguments in a program
#include <stdio.h>
#include <conio.h>
int main(int argc, char *argv[])
{ Compile the above code using command: gcc
int i; name_of_file.c, then run it using: ./[Link]
if( argc >= 2 ) Welcome to Studytonight, we have provided
{ command line argument while running the
printf("The arguments supplied are:\n"); compiled code.
for(i = 1; i < argc; i++)
{
printf("%s\t", argv[i]); 1 : Welcome
} 2 : to
}
3 : Studytonight
else
{
printf("argument list is empty.\n");
}
return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 85
Programming Using C
Example: Simple example which checks if there is any argument supplied from the
command line and takes action accordingly
#include <stdio.h>
int main( int argc, char *argv[] ) {
if( argc == 2 ) {
printf("The argument supplied is %s\n", argv[1]);
}
else if( argc > 2 ) {
printf("Too many arguments supplied.\n");
}
else {
printf("One argument expected.\n");
}
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 86
Programming Using C
When the above code is compiled and executed with a single argument, it
produces the following result.
$./[Link] testing
The argument supplied is testing
When the above code is compiled and executed with two arguments, it produces
the following result.
$./[Link] testing1 testing2
Too many arguments were supplied.
When the above code is compiled and executed without passing any argument, it
produces the following result.
$./[Link]
One argument expected
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 87
Programming Using C
Example once again where we will print the program name and we also pass a
command line argument by putting inside double quotes.
#include <stdio.h>
int main( int argc, char *argv[] ) {
printf("Program name %s\n", argv[0]);
if( argc == 2 ) {
printf("The argument supplied is %s\n", argv[1]);
}
else if( argc > 2 ) {
printf("Too many arguments supplied.\n");
}
else {
printf("One argument expected.\n");
}
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 88
Programming Using C
When the above code is compiled and executed with a single argument
separated by space but inside double quotes, it produces the following result.
$./[Link] "testing1 testing2"
Program name ./[Link]
The argument supplied is testing1 testing2
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 89
Programming Using C
Character Pointers
A pointer may be a special memory location that’s capable of holding the
address of another memory cell. So a personality pointer may be a pointer that
will point to any location holding character only.
A character pointer only stores an address of a character variable.
Syntax: char *ptr;
A character array is employed to store characters in Contiguous Memory
Locations. char * and char [] both want to access the character array.
Though functionally both are the same, they’re syntactically different. Since the
content of any pointer is an address, the size of all kinds of pointers ( character,
int, float, double) is 4.
char arr[] = “Hello World”; // Array Version
char ptr* = “Hello World”; // Pointer Version
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 90
Programming Using C
#include<stdio.h>
#include<string.h>
int main ()
{
char str[10];
char *ptr;
printf ("enter a character:\n");
gets (str);
puts (str);
ptr = str;
printf ("name = %c", *ptr);
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 91
Programming Using C
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int n, i;
char *ptr;
printf ("Enter number of characters to store: ");
scanf ("%d", &n);
ptr = (char *) malloc (n * sizeof (char));
for (i = 0; i < n; i++)
{
printf ("Enter ptr[%d]: ", i);
/* notice the space preceding %c is
necessary to read all whitespace in the input buffer
*/
scanf (" %c", ptr + i);
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 92
Programming Using C
printf ("\nPrinting elements of 1-D array: \n\n");
for (i = 0; i < n; i++)
{
printf ("%c ", ptr[i]);
}
return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 93
Programming Using C
#include<stdio.h>
int main()
{
char str[11] = "HelloWorld"; Output: HelloWorld
char *ptr = str;
while (*ptr != '\0’) {
printf("%c", *ptr);
ptr++;
}
return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 94
Programming Using C
#include<stdio.h>
int main() {
char *strPtr = "HelloWorld"; Output: HelloWorld
char *temp = strPtr;
while (*temp != '\0') {
printf("%c", *temp);
temp++;
}
return 0;
}
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 95
Programming Using C
Print string in array with pointer // jth character of string str[i] can be
#include<stdio.h> // accessed from the location
int main() { str[i]+j
while (*(str[i] + j) != '\0') {
char *str[4] = { printf("%c", *(str[i]+j));
"String", j++;
"Topics", }
printf("\n");
"Hello", }
"World" return 0;
}
};
Output:
int i = 0; String
for (i = 0; i < 4; i++) { Topics
Hello
int j = 0; World
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 96
Programming Using C
C program for Pointers with Strings
#include<stdio.h> printf("%c", *(subjects[i] + j));
int main() { j++;
}
char subjects[5][20]; // because j is at the end of the ith string
int i, j; // it indicates size of the string
printf("Enter five different subjects\n"); printf(" <- size = %d\n", j);
for(i = 0; i < 5; i++) { }
scanf("%s", subjects[i]); return 0;
}
}
Output:
printf("The name of subjects are \n"); Enter five different subjects
for(i = 0; i < 5; i++) { Maths Science Geography History English
j = 0; The name of subjects are
while (*(subjects[i] + j) != '\0’) Maths <- size = 5
Science <- size = 7
// jth character of the string at index i
Geography <- size = 9
// is *(subjects[i] + j) History <- size = 7
{ English <- size = 7
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 97
Programming Using C
• String is a data type that stores the sequence of characters in an
array. Every string terminates with a null character (\0), indicating its
termination.
• A pointer to a string in C can be used to point to the base address of
the string array, and its value can be dereferenced to get the value of
the string.
• To get the value of the string array is iterated using a while loop until
a null character is encountered.
• Instead of using arrays, we can use character pointers to store a
string value.
• To store multiple strings, we can use a 2D array or a pointer variable.
Using a 2D array leads to memory wastage because the size of the
columns is fixed for every row in a 2D array in C. This can be
overcome using pointers.
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 98
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 99
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 100
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 101
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 102
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 103
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 104
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 105
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 106
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 107
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 108
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 109
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 110
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 111
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 112
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 113
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 114
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 115
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 116
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 117
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 118
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 119
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 120
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 121
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 122
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 123
Programming Using C
CSE 108/ CSC 108 - Introduction to Computer Science and
07-01-2023 124
Programming Using C