Accessing Structure Variable in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:05:00

1K+ Views

The structure is a user-defined data type, which is used to store a collection of different data types of data.The structure is similar to an array. The only difference is that an array is used to store the same data types whereas, the structure is used to store different data types.The keyword struct is for declaring the structure.Variables inside the structure are the members of the structure.A structure can be declared as follows −Struct structurename{    //member declaration };ExampleFollowing is the C program for accessing a structure variable − Live Demostruct book{    int pages;    float price;    char author[20]; ... Read More

Access Array Element in C Language

Bhanu Priya
Updated on 08-Mar-2021 10:02:11

7K+ Views

An array is a group of related data items that share a common name. A particular value in an array is identified by using its "index number" or "subscript".The advantage of an array is as follows −The ability to use a single name to represent a collection of items and to refer to an item by specifying the item number enables the user to develop concise and efficient programs.The syntax for declaring array is as follows −datatype array_name [size];For example, float height [50]This declares ‘height’ to be an array containing 50 float elements.int group[10]This declares the ‘group’ as an array ... Read More

Find Profit or Loss in Buying an Article using C Program

Bhanu Priya
Updated on 08-Mar-2021 09:55:39

355 Views

The formula for finding profit is as follows if the selling price is greater than cost price −profit=sellingPrice-CosePrice;The formula for finding loss is as follows if cost price is greater than selling price −loss=CostPrice-SellingPriceNow, apply this logic in the program and try to find whether the person gets a profit or loss after buying any article −ExampleFollowing is the C program to find the profit or loss − Live Demo#include int main(){    float CostPrice, SellingPrice, Amount;    printf(" Enter the product Cost : ");    scanf("%f", &CostPrice);    printf(" Enter the Selling Price) : ");    scanf("%f", &SellingPrice);    if ... Read More

Write Temperature Conversion Table Using Function

Bhanu Priya
Updated on 08-Mar-2021 09:53:40

1K+ Views

Temperature conversion is nothing but converting Fahrenheit temperature to Celsius or Celsius to Fahrenheit.In this programming, we are going to explain, how to convert the Fahrenheit temperature to Celsius temperature and how to represent the same in the form of the table by using a function.ExampleFollowing is the C program for temperature conversion − Live Demo#include float conversion(float); int main(){    float fh,cl;    int begin=0,stop=300;    printf("Fahrenheit \t Celsius");// display conversion table heading    printf("----------\t-----------");    fh=begin;    while(fh

What is a Buffer in C Language?

Bhanu Priya
Updated on 08-Mar-2021 09:50:04

11K+ Views

A temporary storage area is called buffer. All input output (I/O) devices contain I/O buffer.When we try to pass more than the required number of values as input then, the remaining values will automatically hold in the input buffer. This buffer data automatically go to the next input functionality, if it is exists.We have to clear the buffer before the next input is taken in.ExampleFollowing is the C program for buffer −#include void main(){    int a, b;    printf(" Enter a value: ");    scanf("%d", &a);    printf(" Enter b value: ");    scanf("%d", &b);    printf(" a+b=%d ", ... Read More

Variable Declaration, Initialization, and Assignment in C Language

Bhanu Priya
Updated on 08-Mar-2021 07:16:24

12K+ Views

The main purpose of variables is to store data in memory. Unlike constants, it will not change during the program execution. However, its value may be changed during execution.The variable declaration indicates that the operating system is going to reserve a piece of memory with that variable name.Variable declarationThe syntax for variable declaration is as follows −type variable_name;ortype variable_name, variable_name, variable_name;For example, iInt a, b; float c; double d;Here, a, b, c, d are variables. The int, float, double are the data types.Variable initializationThe syntax for variable initialization is as follows −data type variablename=value;For example, int width, height=20; char letter='R'; ... Read More

Backslash Character Constants in C Language

Bhanu Priya
Updated on 08-Mar-2021 07:06:32

5K+ Views

A backslash ( \ ) that allows a visual representation of some nongraphic characters introduces an escape.One of the common escape constants is the newline character ( ).Backslash CharactersThe backslash characters are as follows −CharacterMeaning‘\a’alert‘\b’backspace‘\f’form feed‘’newline‘\t’horizontal tab‘\r’carriage return‘\v’vertical tab‘\’backslash‘\’ ’single quote‘\" ’double quote‘\?’Question markExample programFollowing is the C program for the backslash character constants −Example Live Demo#include #define PI 3.14 float area; void main(){    double r;    r=1.0;    area = PI * r * r;    printf("Area is %d ", area); // /n is used to enter the next statement in newline }OutputArea is 1492442840Read More

Convert Hexadecimal and Decimal to Integer Value Using C Language

Bhanu Priya
Updated on 08-Mar-2021 07:03:39

8K+ Views

ProblemHow to convert the hexadecimal value to integer value by using the C programming language?Explain the concept.SolutionHexadecimal values represent in 16 symbols 1 to 9 & A to F. Here, A to F decimal equivalent is 10 to 15.ExampleFollowing is the C program for converting hexadecimal to an integer by using functions −#include #include #include int hextodc(char *hex){    int y = 0;    int dec = 0;    int x, i;    for(i = strlen(hex) - 1 ; i >= 0 ; --i)//{       if(hex[i]>='0'&&hex[i]

Pointer to a Constant in C Language

Bhanu Priya
Updated on 08-Mar-2021 07:00:06

716 Views

The value of the pointer address is constant that means we cannot change the value of the address that is pointed by the pointer.A constant pointer is declared as follows −Data_Type const* Pointer_Name;For example, int const *p// pointer to const integerExampleFollowing is the C program to illustrate a pointer to a constant −#include int main(void){    int var1 = 100;    // pointer to constant integer    const int* ptr = &var1;    //try to modify the value of pointed address    *ptr = 10;    printf("%d", *ptr);    return 0; }OutputWhen the above program is executed, it produces the ... Read More

Access Variables of Int and Float Without Initializing in C

Bhanu Priya
Updated on 08-Mar-2021 06:48:26

2K+ Views

ProblemDeclare int and float variables without initializing and try to print their values in C language. Explain what will happen.SolutionIf a variable is declared but not initialized or uninitialized and if those variables are trying to print, then, it will return 0 or some garbage value.Whenever we declare a variable, a location is allocated to that variable. The only thing is with the help of initialization, we are trying to occupy the memory location which is already allotted while declaration.But in the below program, we are not initializing the values in the memory locations which are reserved. But, by default, ... Read More

Advertisements