Found 1339 Articles for C

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

863 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

639 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

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

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

5K+ 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.

How to debug a core in C/C++?

Ankith Reddy
Updated on 24-Jun-2020 06:17:58

491 Views

A process dumps core when it is terminated by the operating system due to a fault in the program. The most typical reason this occurs is that the program accessed an invalid pointer value like NULL or some value out of its memory area. As part of that process, the operating system tries to write our information to a file to allow us to analyze what happened.This core can be used as follows to diagnose and debug our program −The core is dumped to the /proc/sys/kernel directory by default. To debug a core, the program must be compiled with the ... Read More

How can I get the list of files in a directory using C/C++?

Chandu yadav
Updated on 27-Jan-2020 12:32:32

2K+ Views

Standard C++ doesn't provide a way to do this. You could use the system command to initialize the ls command as follows −Example#include int main () {    char command[50] = "ls -l";    system(command);    return 0; }OutputThis will give the output −-rwxrwxrwx 1 root root  9728 Feb 25 20:51 a.out -rwxrwxrwx 1 root root   131 Feb 25 20:44 hello.cpp -rwxrwxrwx 1 root root   243 Sep  7 13:09 hello.py -rwxrwxrwx 1 root root 33198 Jan  7 11:42 hello.o drwxrwxrwx 0 root root   512 Oct  1 21:40 hydeout -rwxrwxrwx 1 root root    42 Oct 21 11:29 ... Read More

Why can't variables be declared in a switch statement in C/C++?

George John
Updated on 27-Jan-2020 12:30:17

1K+ Views

Variables can be declared in a switch statement. You'll just need to declare them and use them within a new scope in the switch statement. For example,Example#include using namespace std; int main() {    int i = 10;    switch(i) {       case 2:       //some code       break;       case 10:{          int x = 13;          cout

Advertisements