Found 1452 Articles for C

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

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

2K+ 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

8K+ 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

Scope Rules in C

Samual Sam
Updated on 24-Jun-2020 10:59:47

215 Views

In C language, scope is a region of program where identifiers or variables are directly accessible.There are two categories of scope rules in C language.Global VariablesGlobal variables are declared and defined outside any function in the program. They hold their values throughout the lifetime of program. They are accessible throughout the execution of program.Here is an example of global variables in C language, Example Live Demo#include int s; int main () {    int a = 15;    int b = 20;    s = a+b;    printf ("a = %d b = %d s = %d", a, b, s); ... Read More

ftell() in C

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

10K+ 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

fseek() in C/C++

Samual Sam
Updated on 24-Jun-2020 11:01:26

1K+ Views

fseek() in C language, is use to move file pointer to a specific position. Offset and stream are the destination of pointer, is given in the function parameters. If successful, it returns zero. If it is not successful, it returns non-zero value.Here is the syntax of fseek() in C language, int fseek(FILE *stream, long int offset, int whence)Here are the parameters used in fseek()stream − This is the pointer to identify the stream.offset − This is the number of bytes from the position.whence − This is the position from where offset is added.whence is specified by one of the following ... Read More

Bitwise Operators in C

karthikeya Boyini
Updated on 24-Jun-2020 11:01:54

370 Views

Bitwise operators are used to perform bit-level operations on two variables. Here is the table of bitwise operators in C language,OperatorsName of Operators&Bitwise AND|Bitwise OR^Bitwise XOR~Bitwise complementShift rightHere is an example of bitwise operators in C language,Example Live Demo#include int main() {    int x = 10;    int y = 28;    int i = 0;    printf("Bitwise AND : %d", x&y);    printf("Bitwise OR : %d", x|y);    printf("Bitwise XOR : %d", x^y);    printf("Bitwise Complement : %d,%d", ~x,~-y);    for(i;i>i);    for(i;i

Relational and Logical Operators in C

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

15K+ 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

17K+ 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

1K+ 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

Storage Classes in C

Samual Sam
Updated on 24-Jun-2020 10:56:17

2K+ Views

In C language, the features of variables and functions are described by the storage classes like visibility and scope of q variable or function.There are four types of storage classes in C language: Automatic variables, External variables, Static variables, and Register variables.autoAuto storage class is the default storage class for all the local variables. It is created when function is called. When the execution of function is completed, variables are destroyed automatically.They are also known as local variables because they are local to a function. By default, they are assigned the garbage value by the compiler.Scope − auto variables are ... Read More

Advertisements