Bhanu Priya

Bhanu Priya

1,060 Articles Published

Articles by Bhanu Priya

Page 105 of 106

What do you mean by buffer in C language?

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 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

Explain the variable declaration, initialization and assignment in C language

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 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

What are Backslash character constants in C language?

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 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 1492442840

Read More

Accessing variables of Int and Float without initializing in C

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 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

Given an example of C pointer addition and subtraction

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 3K+ Views

Pointers have many but easy concepts and they are very important to C programming.Two of the arithmetic pointer concepts are explained below, which are C pointer addition and subtraction respectively.C pointer additionC pointer addition refers to adding a value to the pointer variable.The formula is as follows −new_address= current_address + (number * size_of(data type))ExampleFollowing is the C program for C pointer addition − Live Demo#include int main(){    int num=500;    int *ptr;//pointer to int    ptr=#//stores the address of number variable    printf("add of ptr is %u ", ptr);    ptr=ptr+7; //adding 7 to pointer variable    printf("after adding add ...

Read More

Compute sum of all elements in 2 D array in C

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 4K+ Views

ProblemCalculate the sum of all elements of a two-dimensional array by using run-time initialization.SolutionTwo-dimensional Array is used in situations where a table of values have to be stored (or) in matrices applicationsThe syntax is as follows −datatype array_ name [rowsize] [column size];For example, int a[4] [4];Number of elements in an array = rowsize *columnsize = 4*4 = 16ExampleFollowing is the C program to calculate the sum of all elements of a two-dimensional array by using run-time initialization − Live Demo#include void main(){    //Declaring array and variables//    int A[4][3], i, j, even=0, odd=0;    //Reading elements into the array//   ...

Read More

Explain volatile and restrict type qualifiers in C with an example

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 1K+ Views

Type qualifiers add special attributes to existing data types in C programming language.There are three type qualifiers in C language and volatile and restrict type qualifiers are explained below −VolatileA volatile type qualifier is used to tell the compiler that a variable is shared. That is, a variable may be referenced and changed by other programs (or) entities if it is declared as volatile.For example, volatile int x;RestrictThis is used only with pointers. It indicates that the pointer is only an initial way to access the deference data. It provides more help to the compiler for optimization.Example ProgramFollowing is the ...

Read More

Explain the constant type qualifier in C language

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 274 Views

Type qualifiers add special attributes to existing datatypes in C programming language.There are three type qualifiers in C language and constant type qualifier is explained below −ConstThere are three types of constants, which are as follows −Literal constantsDefined constantsMemory constantsLiteral constants − These are the unnamed constants that are used to specify data.For example, a=b+7 //Here ‘7’ is literal constant.Defined constants − These constants use the preprocessor command ‘define" with #For example, #define PI 3.1415Memory constants − These constants use ‘C’ qualifier ‘const’, which indicates that the data cannot be changed.The syntax is as follows −const type identifier = valueFor ...

Read More

Decimal to Binary conversion using C Programming

Bhanu Priya
Bhanu Priya
Updated on 08-Mar-2021 4K+ Views

ProblemHow to convert a decimal number to a binary number by using the function in the C programming language?SolutionIn this program, we are calling a function to binary in main(). The called function to binary will perform actual conversion.The logic we are using is called function to convert decimal number to binary number is as follows −while(dno != 0){    rem = dno % 2;    bno = bno + rem * f;    f = f * 10;    dno = dno / 2; }Finally, it returns the binary number to the main program.ExampleFollowing is the C program to ...

Read More

How to calculate sum of random numbers in between 0 to 100 using files in C Programming?

Bhanu Priya
Bhanu Priya
Updated on 06-Mar-2021 2K+ Views

In this program, we are adding random numbers that are generated in between 0 and 100.After every runtime, the result of sum of random numbers is different, i.e., we get a different result for every execution.The logic we use to calculate the sum of random numbers in between 0 to 100 is −for(i = 0; i

Read More
Showing 1041–1050 of 1,060 articles
Advertisements