Programming Articles - Page 1273 of 3366

What are the local static variables in C language?

Sindhura Repala
Updated on 20-Jan-2025 17:20:08

5K+ Views

A local static variable is a variable, whose lifetime doesn’t end with the function call in which it is declared. It extends until the entire programs lifetime. All function calls share the same copy of local static variables. Static Variables A static variable preserves its value across multiple function calls, maintaining its previous value within the scope where it was initialized. These variables are used to count the number of times a function is called. The default value of a static variable is 0. In contrast, normal local scope means that the variables defined within the block are only visible ... Read More

C programs to differentiate array of structures and arrays within a structure

Bhanu Priya
Updated on 26-Mar-2021 06:50:51

795 Views

In C programming language, the most common use of structure is an array of structures.To declare an array of structures, first the structure must be defined and then, an array variable of that type has to be defined.For example,struct book b[10];//10 elements in an array of structures of type ‘book’ExampleFollowing is the C program for the array of structures − Live Demostruct marks{    int sub1;    int sub2;    int sub3;    int total; }; main(){    int i;    struct marks student[3] = {{20,17,11,10},       {175,23,169,10},       {27,56,27,01}};    struct marks total;    for(i = 0; i

C program to compare the structure variables

Bhanu Priya
Updated on 26-Mar-2021 06:47:28

9K+ Views

In C programming language, a structure is a collection of different datatype variables, which are grouped together under a single name.Declaration and initialization of structuresThe general form of a structure declaration is as follows −datatype member1; struct tagname{    datatype member2;    datatype member n; };Here, struct is a keyword.tagname specifies the name of structure.member1, member2 specifies the data items that make up structure.For example, struct book{    int pages;    char author [30];    float price; };Structure variablesThere are three methods of declaring structure variables, which are as follows −First methodstruct book{    int pages;    char author[30];   ... Read More

How to find minimum element in an array using linear search in C language?

Sindhura Repala
Updated on 20-Jan-2025 16:39:20

1K+ Views

Searching for an algorithm is considered as a step-by-step procedure for specifying a data among a large set of data. The C programming language provides two types of searching techniques. They are as follows − Linear search Binary search Linear Search A Linear Search is also known as sequential search, which is a process for finding an item in a list of items. This kind of algorithm checks each element of the list one by one until a match is found in the total list . ... Read More

Explain queue by using linked list in C language

Bhanu Priya
Updated on 26-Mar-2021 06:52:11

1K+ Views

Queue overflow and Queue under flow can be avoided by using linked list.Operations carried out under queue with the help of linked lists in C programming language are as follows −InsertDeleteInsertionThe syntax is as follows −Syntax&item : Newnode = (node*) mallac (sizeof (node)); newnode ->data = item; newnode ->link = NULL; if ((front = = NULL) || (rear = = NULL)){    front= newnode;    rear = newnode; }else{    Rear->link = newnode;    rear = newnode; }DeletionThe syntax is as follows −Syntaxif ((front= = NULL)) printf("Deletion is not possible, Queue is empty"); else{    temp = front;    front ... Read More

Explain the stack by using linked list in C language

Bhanu Priya
Updated on 26-Mar-2021 06:47:11

3K+ Views

Stack over flow and stack under flow can be avoided by allocating memory dynamically.Operations carried out under stack in C programming language are as follows −PushPopPushFollowing is the basic implementation of a linked list −&item = 10 newnode = (node*) malloc (sizeof (node)); newnode ->data = item; newnode ->link = NULL; newnode ->link = start; start = newnode;popThe syntax is as follows −Syntaxif (start = = NULL) printf("Deletion is not possible.List is empty") else{    temp = start;    start = start link;    free (temp); }ProgramFollowing is the C program for stack by using linked lists −#include #include ... Read More

Explain the deletion of element in linked list

Bhanu Priya
Updated on 26-Mar-2021 06:40:12

761 Views

Linked lists use dynamic memory allocation i.e. they grow and shrink accordingly. They are defined as a collection of nodes. Here, nodes have two parts, which are data and link. The representation of data, link and linked lists is given below −Operations on linked listsThere are three types of operations on linked lists in C language, which are as follows −InsertionDeletionTraversingDeletionConsider an example given below −Delete node 2Delete node 1Delete node 3ProgramFollowing is the C program for deletion of the elements in linked lists − Live Demo#include #include struct Node{    int data;    struct Node *next; }; void ... Read More

Explain deleting an element in a queue by using C language

Bhanu Priya
Updated on 20-Jun-2024 21:39:11

7K+ Views

Data structure is collection of data organized in a structured way. It is divided into two types as explained below −Linear data structure − Data is organized in a linear fashion. For example, arrays, structures, stacks, queues, linked lists.Nonlinear data structure − Data is organized in a hierarchical way. For example, Trees, graphs, sets, tables. Also Read: Data Structures and Types Queue Queue is a linear data structure, where the insertion is done at rear end and the deletion is done at the front end.The order of queue is FIFO – First In First OutOperationsInsert – Inserting an element into ... Read More

What are the inserting elements in queue in C language?

Bhanu Priya
Updated on 20-Jun-2024 21:43:55

5K+ Views

Data structure is collection of data organized in a structured way. It is divided into two types as explained below − Linear data structure − Data is organized in a linear fashion. For example, arrays, structures, stacks, queues, linked lists. Nonlinear data structure − Data is organized in a hierarchical way. For example, Trees, graphs, sets, tables. Read Also: Data Structures and Types Queue Queue is a linear data structure, where the insertion is done at rear end ... Read More

C program to sort names in alphabetical order with string functions.

Bhanu Priya
Updated on 26-Mar-2021 06:43:54

991 Views

ProblemSort the names given by the user at runtime in an alphabetical order by using the bubble sort technique.SolutionThe logic used to print the names in alphabetical order is as follows −for (i=1; i < ITEMS; i++){    for (j=1; j 0){ /* Exchange of contents */          strcpy (dummy, string[j-1]);          strcpy (string[j-1], string[j]);          strcpy (string[j], dummy );       }    } }ExampleFollowing is the C program to sort the names in an alphabetical order by using the string functions − Live Demo#define ITEMS 5 #define MAXCHAR ... Read More

Advertisements