Skip to content

Programming Articles

  • HOME
  • Python
  • JavaScript
  • C/C++
  • Java
  • Terms & Conditions and Privacy Policy
  • About US
Main Menu

C/C++

Articles related to C and C++ programming languages.

C/C++

How to profile C++ code running on Linux?

If your goal is to use a profiler, use one of the suggested ones. However, if you’re in a hurry and you can manually interrupt your program under the debugger …

How to profile C++ code running on Linux? Learn More
C/C++

How to determine the size of an array in C?

In this post, you’ll learn how to find the number of elements the array can hold in C. How to determine the size of an array in C? You can …

How to determine the size of an array in C? Learn More
C/C++

How to iterate over the words of a string in C++?

In this post, we’ll learn how to iterate through a string word by word in C++. How to iterate through a string word by word in C++? Use this to …

How to iterate over the words of a string in C++? Learn More
C/C++ / Explanations

explicit keyword in C++

Short explanation: Suppose, you have a class String: Now, if you try: The character ‘x’ will be implicitly converted to int and then the String(int) constructor will be called. But, this is not what the user might …

explicit keyword in C++ Learn More
C/C++

What is the “–>” operator in C/C++? [Answered]

Query: Here’s the code: Output: I’d assume this is C, since it works in GCC as well. Where is this defined in the standard, and where has it come from? …

What is the “–>” operator in C/C++? [Answered] Learn More
C/C++

How to use extern to share variables between source files in C? [Answered]

Query explanation: I know that global variables in C sometimes have the extern keyword. What is an extern variable? What is the declaration like? What is its scope? This is related to sharing variables …

How to use extern to share variables between source files in C? [Answered] Learn More
C/C++ / Formatted Codes

How to remove trailing newline character from fgets() input? [Answered]

Sample problem: I am trying to get some data from the user and send it to another function in gcc. The code is something like this. However, I find that …

How to remove trailing newline character from fgets() input? [Answered] Learn More
C/C++

How to find the size of a pointer pointing to an array? [Answered]

Query explained: First off, here is some code: Is there a way to find out the size of the array that ptr is pointing to (instead of just giving its size, which …

How to find the size of a pointer pointing to an array? [Answered] Learn More
C/C++

What are the differences between a pointer variable and a reference variable in C++?

Query: I know references are syntactic sugar, so code is easier to read and write. But what is the difference between a pointer variable and a reference variable? What are …

What are the differences between a pointer variable and a reference variable in C++? Learn More
C/C++ / Java / Programming

Why is it faster to process a sorted array than processing an unsorted array? [Answered]

Query explained: Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost …

Why is it faster to process a sorted array than processing an unsorted array? [Answered] Learn More
C/C++

How to resolve build errors due to circular dependency amongst classes? [Answered]

Sample problem: I often find myself in a situation where I am facing multiple compilation/linker errors in a C++ project due to some bad design decisions (made by someone else …

How to resolve build errors due to circular dependency amongst classes? [Answered] Learn More
C/C++

What is the copy-and-swap idiom? [Answered]

Query: What is the copy-and-swap idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used? The copy-and-swap idiom- Answer #1: …

What is the copy-and-swap idiom? [Answered] Learn More
C/C++ / Formatted Codes

How to iterate over the words of a string in C++? [Answered]

I’m trying to iterate over the words of a string. The string can be assumed to be composed of words separated by whitespace. Note that I’m not interested in C …

How to iterate over the words of a string in C++? [Answered] Learn More
C/C++ / Formatted Codes

scanf() leaves the new line char in the buffer | C [Answered]

Sample problem: I have the following program: As I read in the C book, the author says that scanf() left a new line character in the buffer, therefore, the program does not …

scanf() leaves the new line char in the buffer | C [Answered] Learn More
C/C++ / Linux

How to profile C++ code running on Linux? [Answered]

Query: I have a C++ application, running on Linux, which I’m in the process of optimizing. How can I pinpoint which areas of my code are running slowly? How to …

How to profile C++ code running on Linux? [Answered] Learn More
C/C++

What are the rules about using an underscore in a C++ identifier? [Answered]

Query: It’s common in C++ to name member variables with some kind of prefix to denote the fact that they’re member variables, rather than local variables or parameters. If you’ve …

What are the rules about using an underscore in a C++ identifier? [Answered] Learn More
C/C++ / Formatted Codes

What is Object Slicing in C++? [Answered]

Object slicing in C++: Answer #1: “Slicing” is where you assign an object of a derived class to an instance of a base class, thereby losing part of the information …

What is Object Slicing in C++? [Answered] Learn More

Posts navigation

1 2 Next

Featured Posts

History of UNIX

From UNIX to Linux – History of Linux

21st November 202013th November 2021

Top themes for Ubuntu

Best themes for Ubuntu: Make Ubuntu Beautiful

20th October 202029th November 2021

Strings in Python

Strings in Python

12th September 202010th November 2021

is python hard to learn

Is Python hard to learn? Top best learning resources

18th April 202013th November 2021

Recent posts

  • How to recursively grep all directories and subdirectories?
  • How to merge two Git repositories?
  • What is the main difference between an inner class and a static nested class in Java?
  • RegEx to match open tags except XHTML self-contained tags
  • How to count the occurrences of a list item in Python?
  • Why is it string.join(list) instead of list.join(string)?
Copyright © 2022 Programming Articles.
Powered by WordPress and HitMag.