Found 1443 Articles for C

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

Priya Pallavi
Updated on 27-Jan-2020 12:35:13
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
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
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 -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
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

What does int argc, char *argv[] mean in C/C++?

Chandu yadav
Updated on 24-Jun-2020 06:12:03
argc stands for argument count and argv stands for argument values. These are variables passed to the main function when it starts executing. When we run a program we can give arguments to that program like −$ ./a.out helloExampleHere hello is an argument to the executable. This can be accessed in your program. For example,#include using namespace std; int main(int argc, char** argv) {    cout

Why do we use extern "C" in C++ code?

Priya Pallavi
Updated on 30-Jul-2019 22:30:22
You need to use extern "C" in C++ when declaring a function that was implemented/compiled in C.Using extern "C" lets the compiler know that we want to use C naming and calling conventions. This causes the compiler to sort of entering C mode inside our C++ code. This is needed because C++ compilers mangle the names in their symbol table differently than C compilers and hence behave differently than C compilers.

Is C++0x Compatible with C?

Srinivas Gorla
Updated on 30-Jul-2019 22:30:22
Neither C++ (98) nor the new standard(C++0x or C++11) is fully compatible with C. C++ never was fully compatible with C.

How can I write in order with for loop or while loop?

Arnab Chakraborty
Updated on 20-Jun-2020 15:34:17
Example#include #include void main() {    int i,j,a=0,b=1,n;    clrscr();    printf("****************OUTPUT*****************");    printf("enter the value of n : ");    scanf("%d",&n);    printf(" the required order is: " );    for(i=1;i

How do I set up C/C++ on Eclipse in Windows?

Updated on 26-Feb-2020 11:21:22
Step 1 − Install MinGW GCC or Cygwin GCCTo use Eclipse for C/C++ programming, you need a C/C++ compiler. On Windows, you could install either MinGW GCC or Cygwin GCC. Choose MinGW if you are not sure, because MinGW is lighter and easier to install, but has fewer features.MinGW GCCTo install MinGW, go to the MinGW homepage,, and follow the link to the MinGW download page. Download the latest version of the MinGW installation program which should be named MinGW .exe.While installing MinGW, at a minimum, you must install gcc-core, gcc-g++, binutils, and the MinGW runtime, but you may ... Read More

When to use C over C++, and C++ over C?

Kumar Varma
Updated on 18-Jun-2020 13:05:03
If you would like an application that works directly with computer hardware or deals with the desktop app development, C++ is an good option. C++ programs include server-side applications, networking, gaming, and even device drivers for your PC. However, if you need to code truly tiny systems, using C will result in less overhead than C++.C++ is well-rounded in terms of platforms and target applications, so if your project is focused on extremely low-level processing, then you may want to use C++. C++ is often used for large-scale, multi-man, complex projects where separate people need to work on modularised components. ... Read More