C Articles

Page 16 of 96

What is a structure at local scope in C language?

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 991 Views

Structure is a collection of different datatype variables, grouped together under a single name.General form of structure declarationThe structure declaration is as follows −struct tagname{    datatype member1;    datatype member2;    datatype member n; };Here, struct is the keyword.tagname specifies name of structure.member1, member2 specifies the data items that make up structure.ExampleThe following example shows the usage of the structure at a local scope.struct book{    int pages;    char author [30];    float price; };ExampleThe following program shows the usage the structure at a local scope.#include struct{    char name[20];    int age;    int salary;    char ...

Read More

Explain the pointers to unions in C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 4K+ Views

A union is a memory location that is shared by several variables of different data types.SyntaxThe syntax for the pointers to unions in C programming is as follows −union uniontag{    datatype member 1;    datatype member 2;    ----    ----    datatype member n; };ExampleThe following example shows the usage of union of structure.union sample{    int a;    float b;    char c; };Declaration of union variableFollowing is the declaration for union variable. It is of three types as follows −Type 1union sample{    int a;    float b;    char c; }s;Type 2union{    int a; ...

Read More

Explain the Character operations in C language

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 696 Views

Character can be (A-Z(or) a- z), digit (0-9), a white space, or a special symbol in C programming language.DeclarationFollowing is the declaration for character operations in C programming −char a= ‘A’; using a character constant.Character input / output functionsThe character input/output functions are explained below −Example − char a;scanf("%c", &a); printf ("%c", &a); a = getchar ( ); putchar (a); a = getch ( ); putch (a);ExampleFollowing is the C program for line counting using getchar() −#include /* count lines in input */ main(){    int count, num;    printf("enter multiple statements and Press cntrl+z:");    num = 0; ...

Read More

Write a C Program to count the frequency of each character

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 934 Views

Follow the algorithm to write a C program which enables to count the frequency of each character.AlgorithmStep 1: Define MAX size. Step 2: Declare char and integer variables. Step 3: Read the string from console. Step 4: Find length of the string. Step 5: Initialize frequency of each character to 0. Step 6: Find total number of occurrences of each character. for(i=0; i='a' && string[i]='A' && string[i]

Read More

C Program to calculate the difference between two time periods

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 4K+ Views

Enter the start and stop time with hours, minutes and seconds. Finally, we need to find the difference between start and stop time.The logic to find the difference between start and stop time is given below −while (stop.sec > start.sec){    --start.min;    start.sec += 60; } diff->sec = start.sec - stop.sec; while (stop.min > start.min) {    --start.hrs;    start.min += 60; } diff->min = start.min - stop.min; diff->hrs = start.hrs - stop.hrs;ExampleFollowing is the program to find difference between start and stop time −#include struct time {    int sec;    int min;    int hrs; }; ...

Read More

C program to rotate the bits for a given number

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ Views

Consider the factors given below to write a C program to rotate the bits for a given number.Rotating the bit from left to right or right to left.In left rotation, the bits are shifted from left to right.In right rotation, the bits are shifted from right to left.Take a number and try to rotate either left or right based on user program.User has to enter the number rotation at run time along with a number.Program 1Following is the C program to apply left rotation for a given number.#include #include int main(){    int number, rotate, Msb, size;    printf("Enter any ...

Read More

C Program to count trailing and leading zeros in a binary number

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ Views

To begin with, let us understand what are trailing zeros in a binary number.Trailing zerosThe position of zeros after first one from the least significant bit (LSB) is called as trailing zeros in binary number.Example104 is decimal numberBinary number of 104 is: (MSB) 1101000(LSB)Here, MSB refers to Most Significant Bit.LSB refers to Least Significant Bit.From LSB after the first bit set, there are three zero.The number of trailing zeros is three.ExampleFollowing is the program to count number of trailing zeros for a given number −#include #include int main(){    int number, i, trail = 0, size;    printf("Enter a number"); ...

Read More

What is enumerated data type in C language?

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ Views

These are used by the programmers to create their own data types and define what values the variables of these datatypes can hold.The keyword is enum.SyntaxThe syntax for enumerated data type is as follows −enum tagname{    identifier1, identifier2, ……., identifier n };ExampleGiven below is an example for enumerated data type −enum week{    mon, tue, wed, thu, fri, sat, sun };Here, Identifier values are unsigned integers and start from 0.Mon refers 0, tue refers 1 and so on.ExampleFollowing is the C program for enumerated data type −#include main ( ){    enum week {mon, tue, wed, thu, fri, sat, ...

Read More

C Program to find two’s complement for a given number

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 18K+ Views

The two’s complement for a given binary number can be calculated in two methods, which are as follows −Method 1 − Convert the given binary number into one’s complement and then, add 1.Method 2 − The trailing zero’s after the first bit set from the Least Significant Bit (LSB) including one that remains unchanged and remaining all should be complementing.The logic to find two’s complement for a given binary number is as follows −for(i = SIZE - 1; i >= 0; i--){    if(one[i] == '1' && carry == 1){       two[i] = '0';    }    else ...

Read More

Program to check if a string contains any special character in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 7K+ Views

Given a string str[], the task is to check whether the string contains any special character and if the string have a special character then print “The String is not accepted” else print “The string is accepted”.Special characters are those characters which are neither numeric nor alphabetic i.e. − !@#$%^&*()+=-\][‘;/., {}|:”?`~So in C Programming language we will use if-else approach to solve the problem.Input − str[] = {“tutorials-point”}Output − the string is not acceptedInput − str[] = {“tutorialspoint”}Output − The string is acceptedApproach used below is as follows to solve the problem −Traverse the whole string.Will look for the special ...

Read More
Showing 151–160 of 953 articles
« Prev 1 14 15 16 17 18 96 Next »
Advertisements