Found 1401 Articles for C

Explain Compile time and Run time initialization in C programming?

Bhanu Priya
Updated on 09-Mar-2021 07:18:46

15K+ Views

Let’s take the concept of arrays to about compile time and run time initialization −ArrayArray is a collection of items stored at contiguous memory locations and elements can access by using indices.Compile time array initializationIn compile time initialization, user has to enter the details in the program itself.Compile time initialization is same as variable initialization. The general form of initialization of array is as follows −Syntaxtype name[size] = { list_of_values }; //integer array initialization int rollnumbers[4]={ 2, 5, 6, 7}; //float array initialization float area[5]={ 23.4, 6.8, 5.5, 7.3, 2.4 }; //character array initialization char name[9]={ 'T', 'u', 't', 'o', ... Read More

Why is the compiler not reading string after integer in C programming?

Bhanu Priya
Updated on 09-Mar-2021 07:17:09

2K+ Views

ProblemCompiler not reading the string after integer in C programming? How can we solve this problem?SolutionWhen you enter an integer number and press enter to read next value, compiler stores null into the string’s first char and string input terminates. Because scanf will terminate whenever it reads a null character.How to Solve It?When we are trying to read string or character after int or float, we should read a temporary char which is present in the input buffer.The following is the program without errors −Example Live Demo#include struct student{    char name[10];    int roll;    char temp; } s; ... Read More

What is the common error occurred while using scanf() statement in C language?

Bhanu Priya
Updated on 09-Mar-2021 07:14:33

818 Views

ProblemCommon error occurred while reading string and numeric data using scanf() function in C languageSolutionThe scanf() function is used to read formatted input from stdin in C language. It returns the whole number of characters written in it otherwise, returns a negative value.Generally in case of scanf() function while reading string values after integer from the user, we get frequent errors.ExampleFollowing is a C program which reads roll number (integer value) and name of a student − Live Demo#include struct student {    char name[10];    int roll; } s; int main(){    printf("Enter information of students:");    printf("Enter roll ... Read More

How to print a name multiple times without loop statement using C language?

Bhanu Priya
Updated on 09-Mar-2021 07:13:35

6K+ Views

ProblemTry to print a name 10 times without using any loop or goto statement in C programming language.SolutionGenerally, looping statements are used to repeat the block of code until condition is false.Example1In this program, we are trying to print a name 10 times without using loop or goto statements. Live Demo#include void printname(char* name,int count){    printf("%03d : %s",count+1,name);    count+=1;    if(count

Is it possible to give arguments in the main() function in C language?

Bhanu Priya
Updated on 09-Mar-2021 07:10:36

4K+ Views

Yes, we can give arguments in the main() function.Command line arguments in C are specified after the name of the program in the system’s command line, and these argument values are passed on to your program during program execution.The argc and argv are the two arguments that can pass to main function.But main() function is actually called by the operating system (or shell program) when you run the program from the terminal.SyntaxThe syntax is explained below −int main(int argc, char *argv[]){    //Code    return 0; }Example Live Demo#include int main(int argc, char *argv[]){    int i;    for (i = ... Read More

Find the ASCII value of the uppercase character ‘A’ using implicit conversion in C language?

Bhanu Priya
Updated on 09-Mar-2021 07:09:37

357 Views

Implicit type conversion is done by the compiler by converting smaller data type into a larger data type.For example, ASCII value of A=65.In this program, we are giving character ‘A’ as input, now write a code to convert A to 65 which is its ASCII value.ExampleFollowing is the example to find ASCII value of uppercase character ‘A’ using implicit conversion − Live Demo#include int main(){    char character = 'A';    int number = 0, value;    value = character + number; //implicit conversion    printf("The ASCII value of A is: %d", value);    return 0; }OutputThe ASCII value of ‘A’ ... Read More

What are implicit and explicit type conversions in C language?

Bhanu Priya
Updated on 22-Oct-2023 03:13:08

27K+ Views

Converting one data type into another data type is called type conversions.Implicit type conversionExplicit type conversionImplicit type conversionThe compiler provides implicit type conversions when operands are of different data types.It is automatically done by the compiler by converting smaller data type into a larger data type.int i,x; float f; double d; long int l;Here, the above expression finally evaluates to a ‘double’ value.ExampleFollowing is an example for implicit type conversion −int x; for(x=97; x

What are the 4 steps to convert C program to Machine code?

Bhanu Priya
Updated on 09-Mar-2021 07:03:14

4K+ Views

Process of Creating and Running ProgramsA program contains a set of instructions which was written in a programming language.The programmer’s job is to write and test the program.The 4 steps to convert a ‘C’ program into machine language are &miuns;Writing and editing the programCompiling the programLinking the programExecuting the programWriting and editing the program‘Text editors’ are used to write programs.With the help of text editors, users can enter, change and store character data.All special text editors are often included with a compiler.After writing the program, the file is saved to disk.It is known as ‘source file’.This file is input to ... Read More

Significance of Lambda Function in C/C++

Dev Prakash Sharma
Updated on 05-Feb-2021 12:51:35

4K+ Views

Lambda Function − Lambda are functions is an inline function that doesn’t require any implementation outside the scope of the main program.Lambda Functions can also be used as a value by the variable to store. Lambda can be referred to as an object that can be called by the function (called functors).Whenever the compiler encounters a definition of the lambda function, it generally creates a custom object for the lambda.A lambda function has more functionality than a normal function, for example, it has a capturing method to capture the used variables. However, the captured variable is treated as the member ... Read More

Check if a string is palindrome in C using pointers

Arnab Chakraborty
Updated on 29-Dec-2020 13:24:43

7K+ Views

Suppose we have a string s. We have to check whether the given string is a palindrome or not. We have to solve this problem using pointers in C.So, if the input is like s = "racecar", then the output will be True.To solve this, we will follow these steps −length := size of stringforward := pointing to the first character of stringreverse := pointing to the last character of stringwhile position of reverse >= position of forward, doif character pointed by reverse is same as character pointed by forward, thenincrease forward and decrease reverse by 1otherwisecome out from loopif ... Read More

Advertisements