C Articles - Page 132 of 134

puts() vs printf() for printing a string in C language

Samual Sam
Updated on 24-Jun-2020 11:09:13

3K+ Views

The function puts() and printf() are declared in stdio.h header file and are used to send the text to the output stream. Both have different usages and syntax.puts()The function puts() is used to print the string on the output stream with the additional new line character ‘’. It moves the cursor to the next line. Implementation of puts() is easier than printf().Here is the syntax of puts() in C language, puts(“string”);If you do not want the cursor to be moved to the new line, use the following syntax.fputs(string, stdout)Here is an example of puts() in C language, Example Live Demo#include int ... Read More

“register” keyword in C

karthikeya Boyini
Updated on 24-Jun-2020 10:59:13

10K+ Views

Register variables tell the compiler to store the variable in CPU register instead of memory. Frequently used variables are kept in registers and they have faster accessibility. We can never get the addresses of these variables. “register” keyword is used to declare the register variables.Scope − They are local to the function.Default value − Default initialized value is the garbage value.Lifetime − Till the end of the execution of the block in which it is defined.Here is an example of register variable in C language, Example Live Demo#include int main() {    register char x = 'S';    register int ... Read More

ftell() in C

karthikeya Boyini
Updated on 24-Jun-2020 11:00:53

11K+ Views

In C language, ftell() returns the current file position of the specified stream with respect to the starting of the file. This function is used to get the total size of file after moving the file pointer at the end of the file. It returns the current position in long type and file can have more than 32767 bytes of data.Here is the syntax of ftell() in C language, long int ftell(FILE *stream)Here is the parameter used in ftell(), stream − This is the pointer to a FILE object that identifies the stream.Here is an example of ftell() in C ... Read More

Relational and Logical Operators in C

Samual Sam
Updated on 24-Jun-2020 11:02:49

22K+ Views

Relational OperatorsRelational operators are used to compare two values in C language. It checks the relationship between two values. If relation is true, it returns 1. However, if the relation is false, it returns 0.Here is the table of relational operators in C languageOperatorsOperator Name==Equal to>Greater than=Greater than or equal toy)    printf("x is greater than y ");    if(x

“extern” keyword in C

Samual Sam
Updated on 24-Jun-2020 11:03:45

20K+ Views

External variables are also known as global variables. These variables are defined outside the function. These variables are available globally throughout the function execution. The value of global variables can be modified by the functions. “extern” keyword is used to declare and define the external variables.Scope − They are not bound by any function. They are everywhere in the program i.e. global.Default value − Default initialized value of global variables are Zero.Lifetime − Till the end of the execution of the program.Here are some important points about extern keyword in C language, External variables can be declared number of times ... Read More

Pre-increment (or pre-decrement) in C

karthikeya Boyini
Updated on 24-Jun-2020 10:54:34

2K+ Views

Increment operators are used to increase the value by one while decrement works opposite increment. Decrement operator decreases the value by one.Here is the syntax of pre-increment operator in C language, ++variable_name;Here is the syntax of pre-decrement operator in C language, --variable_name;Let us see the difference between pre-increment and pre-decrement operator.Pre-increment − Before assigning the value to the variable, the value is incremented by one.Here is an example of pre-increment in C language, Example Live Demo#include int main() {    int i = 5;    printf("The pre-incremented value : %d", i);    while(++i < 10 )    printf("%d\t", i);   ... Read More

Variables and Keywords in C

Samual Sam
Updated on 24-Jun-2020 10:52:39

12K+ Views

VariablesIn C language, variables are the storage place where some form of data is stored. Different variables require different amount of memory on which a set of operations is applied.A variable name cannot start with a number. It can consist of alphabets, number, underscore “_”.Here is the syntax of declaring variables in C language, type variable_name;Here is the syntax of multiple variables declaration in C language, type variable_name1, variable_name2, variable_name3;The following is an example of variables in C language, Example Live Demo#include int main() {    char a1 = 'H';    int b = 90, c = 150;    float ... Read More

Count spaces, uppercase and lowercase in a sentence using C

Arnab Chakraborty
Updated on 27-Jan-2020 12:45:05

874 Views

#include int main() {    char str[100],i;    int upper = 0, lower = 0, number = 0, special = 0,whitesp=0;    printf("enter string");    gets(str);    for (i = 0; i < str[i]!='\0'; i++) {       if (str[i] >= 'A' && str[i] = 'a' && str[i] = '0' && str[i]

How to convert a string to a integer in C

Pythonista
Updated on 27-Jan-2020 12:41:27

652 Views

First extract characters from left bracket '(' using strchr() function.char *name="The Matrix(1999)"; char *ps; ps=strchr(name,'(');Then add each character within brackets () to an char arraychar y[5]=""; int  p; for (p=1;p

List of Common Reasons for Segmentation Faults in C/C++

Ramu Prasad
Updated on 27-Jan-2020 12:38:34

5K+ Views

The main reason for segmentation fault is accessing memory that is either not initialized, out of bounds for your program or trying to modify string literals. These may cause a segmentation fault though it is not guaranteed that they will cause a segmentation fault. Here are some of the common reasons for segmentation faults −Accessing an array out of boundsDereferencing NULL pointersDereferencing freed memoryDereferencing uninitialized pointersIncorrect use of the "&" (address of) and "*" (dereferencing) operatorsImproper formatting specifiers in printf and scanf statementsStack overflowWriting to read-only memory

Advertisements