Found 1339 Articles for C

What are different pointer operations and problems with pointers in C language?

Bhanu Priya
Updated on 15-Mar-2021 10:13:21

3K+ Views

A pointer is a variable whose value is the address of an another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.Consider the following statement −int qty = 179;The representation of the variable in memory is as follows −You can declare a pointer as follows −Int *p;It means ‘p’ is a pointer variable that holds the address of another integer variable.Address operator (&) is used to initialize a pointer variable.For Example −int qty = 175; int *p; p= &qty;To access the value of ... Read More

State the difference between memcmp and memicmp functions in C language

Bhanu Priya
Updated on 15-Mar-2021 09:58:55

439 Views

Memcmp() and memicmp() compares first n bytes of two blocks of memory.memcmp() performs comparison as unsigned characters.memicmp() performs comparison as characters but, ignore upper case or lower case letters.Both functions return an integer value.Two memory buffers are equal (returns 0).First buffer is greater than second (returns >0).First buffer is less than second(returns0)       printf("buffer st1 is bigger than buffer st2");    if(x

How to swap two numbers without using the third or a temporary variable using C Programming?

Bhanu Priya
Updated on 15-Mar-2021 09:38:38

4K+ Views

With the help of addition and subtraction operations, we can swap two numbers from one memory location to another memory location.AlgorithmThe algorithm is explained below −STARTStep 1: Declare 2 variables x and y. Step 2: Read two numbers from keyboard. Step 3: Swap numbers. //Apply addition and subtraction operations to swap the numbers.    i. x=x+y    ii. y=x-y    iii. x=x-y Step 4: Print x and y values.ProgramFollowing is the C program which explains swapping of two numbers without using third variable or a temporary variable −#include int main(){    int x, y;    printf("enter x and y values:"); ... Read More

How to print the range of numbers using C language?

Bhanu Priya
Updated on 13-Mar-2021 11:41:01

2K+ Views

ProblemFor given number try to find the range in which that number exists.SolutionHere, we are learning how to find the ranges of a number.The logic that we apply to find range is −lower= (n/10) * 10; /*the arithmetic operators work from left to right*/ upper = lower+10;ExplanationLet number n=45Lower=(42/10)*10 // division returns quotient       =4*10 =40Upper=40+10=50Range − lower-upper − 40-50ExampleFollowing is the C program for printing the range of numbers −#include main(){    int n, lower, upper;    printf("Enter a number:");    scanf("%d", &n);    lower= (n/10) * 10; /*the arithmetic operators work from left to right*/    upper ... Read More

Finding sum of first and last digit using divide and modulo operator in C language

Bhanu Priya
Updated on 13-Mar-2021 11:40:17

547 Views

ProblemWhat is the C program to obtain the sum of the first and last digit of the number, if a four-digit number is input through the keyboard?SolutionIn this program, we are taking a four-digit number at run time and trying to find the sum of first and last digit of that four-digit number by using the logic −a=n%10; b=n/1000; result = a + b;Let’s apply this logic to find sum of first and last digit of four-digit number −ExampleFollowing is the C program for finding sum of first and last digit by using divide and modulo operator −#include main(){   ... Read More

What are different operators and expressions used in C language?

Aishwarya Naglot
Updated on 12-Nov-2024 10:37:28

14K+ Views

Operators are special symbols in C that performs an operation on values and variables. These special symbols allow us to manipulate data and variables in different ways. Those Operators are classified into the following − Arithmetic operators. Relational operators. Logical operators. Assignment operators. Increment and decrement operators. Bitwise operators. Conditional operators. Special operators. Expressions in C is a combination of variables, operators, and values that generates ... Read More

Explain the Format of C language

Bhanu Priya
Updated on 11-Mar-2021 08:35:46

2K+ Views

C programming is a general-purpose, procedural, imperative computer programming language. In C language, we see thatStatements are terminated with semicolons.C is case sensitiveIndentation is ignored by the compiler.Strings are placed in double quotes.Library functions are lowercase.Newlines are handled via Format of CThe format of C programming language is explained below −SemicolonsSemicolons are very important in C.It tells the compiler, where one statement ends and the next statement begins.If we fail to place the semicolon after each statement, you will get compilation errors.Case SensitivityC is a case sensitive language. Although, int compiles, "Int”, "INT” or any other variation will not be ... Read More

Check if the value entered is palindrome or not using C language

Bhanu Priya
Updated on 11-Mar-2021 08:28:05

577 Views

A palindrome is nothing but any word, number, sentence, or other sequence of characters that reads the same backward as forward.In this programming, we are trying to enter a number from console, and assign that number to temp variable.If number is greater than zero, apply the logic given below −while(n>0){    r=n%10;    sum=(sum*10)+r;    n=n/10; }If temp=sum, then the given number is a palindrome. Otherwise, it is not a palindrome.ExampleFollowing is the C program for verification of a value being palindrome −#include #include void main(){    int n, r, sum=0, temp;    printf("Enter a number: ");    scanf("%d", &n); ... Read More

Explain the concept of Sorting in C language

Bhanu Priya
Updated on 11-Mar-2021 07:51:40

5K+ Views

ProblemWhy sorting makes searching easier in C language? How can you judge the sorting efficiency in C?SolutionSorting is the process of arranging elements either in ascending (or) descending order.The term sorting came into existence when humans realized the importance of searching quickly.There are different things in life that we need to search for, particular record in database, roll numbers in a list, a number in a telephone directory, a specific page in a book etc.If the data was kept in an unordered and unsorted form, it becomes difficult to search a particular thing. But fortunately, the concept of sorting came ... Read More

Explain the Random accessing files in C language

Bhanu Priya
Updated on 11-Mar-2021 07:20:51

11K+ Views

Random accessing of files in C language can be done with the help of the following functions −ftell ( )rewind ( )fseek ( )ftell ( )It returns the current position of the file ptr.The syntax is as follows −int n = ftell (file pointer)For example, FILE *fp; int n; _____ _____ _____ n = ftell (fp);Note − ftell ( ) is used for counting the number of characters which are entered into a file.rewind ( )It makes file ptr move to beginning of the file.The syntax is as follows −rewind (file pointer);For example, FILE *fp;    -----    -----   ... Read More

Advertisements