Found 1452 Articles for C

Sizeof operator in C

Samual Sam
Updated on 24-Jun-2020 10:58:13

18K+ Views

The sizeof operator is the most common operator in C. It is a compile-time unary operator and used to compute the size of its operand. It returns the size of a variable. It can be applied to any data type, float type, pointer type variables.When sizeof() is used with the data types, it simply returns the amount of memory allocated to that data type. The output can be different on different machines like a 32-bit system can show different output while a 64-bit system can show different of same data types.Here is an example in C language, Example Live Demo#include ... Read More

Typecasting in C

karthikeya Boyini
Updated on 24-Jun-2020 10:48:40

4K+ Views

Typecasting is a method in C language of converting one data type to another.There are two types of typecasting.1.Implicit Type casting − This conversion is done by the compiler. When more than one data type of variables are used in an expression, the compiler converts data types to avoid loss of data.Here is an example of implicit type casting in C language, Example Live Demo#include int main() {    int a = 10;    char b = 'S';    float c = 2.88;    a = a+b;    printf("Implicit conversion from character to integer : %d", a);    c = ... Read More

Data Types in C

Raju Kumar
Updated on 24-Jun-2020 10:58:38

13K+ Views

Variables in C are associated with data type. Each data type requires an amount of memory and performs specific operations.There are some common data types in C −int − Used to store an integer value.char − Used to store a single character.float − Used to store decimal numbers with single precision.double − Used to store decimal numbers with double precision.The following table displays data types in C language −Data TypesBytesRangeshort int2-32, 768 to 32, 767unsigned short int20 to 65, 535unsigned int40 to 4, 294, 967, 295int4-2, 147, 483, 648 to 2, 147, 483, 647long int4-2, 147, 483, 648 to 2, ... Read More

Tokens in C

karthikeya Boyini
Updated on 24-Jun-2020 10:50:32

15K+ Views

Tokens are the smallest elements of a program, which are meaningful to the compiler.The following are the types of tokens: Keywords, Identifiers, Constant, Strings, Operators, etc.Let us begin with Keywords.KeywordsKeywords are predefined, reserved words in C and each of which is associated with specific features. These words help us to use the functionality of C language. They have special meaning to the compilers.There are total 32 keywords in C.autodoubleintstructbreakelselongswitchcaseenumregistertypedefcharexternreturnunioncontinueforsignedvoiddoifstaticwhiledefaultgotosizeofvolatileconstfloatshortunsignedIdentifiersEach program element in C programming is known as an identifier. They are used for naming of variables, functions, array etc. These are user-defined names which consist of alphabets, number, underscore ‘_’. ... Read More

Variables and Keywords in C

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

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

588 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

409 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

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

How does the compilation/linking process work in C/C++?

Chandu yadav
Updated on 27-Jan-2020 12:37:53

3K+ Views

The compilation of a C++ program consists of three steps −Preprocessing − In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. It handles preprocessing directives like #include, #define, etc.Compilation − The compilation takes place on the preprocessed files. The compiler parses the pure C++ source code and converts it into assembly code. This in turn calls the assembler that converts the assembly code to machine code(binary) as Object files. These Object files can refer to symbols that are not defined. The compiler won't give ... Read More

What is a segmentation fault in C/C++?

Priya Pallavi
Updated on 27-Jan-2020 12:35:13

9K+ Views

A segmentation fault occurs when your program attempts to access an area of memory that it is not allowed to access. In other words, when your program tries to access memory that is beyond the limits that the operating system allocated for your program.Seg faults are mostly caused by pointers that are −Used to being properly initialized.Used after the memory they point to has been reallocated or freed.Used in an indexed array where the index is outside of the array bounds.

Advertisements