Programming Articles

Page 2532 of 2547

Difference between #include and #include "filename" in C/C++?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 3K+ Views

The difference between the two forms is in the location where the preprocessor searches for the file to be included.#include The preprocessor searches in an implementation-dependent manner, it searches directories pre-designated by the compiler. This method is usually used to include standard library header files.#include "filename"The preprocessor searches in the same directory as the file containing the directive. If this fails, then it starts behaving like the #include form. This method is usually used to include your own header files.

Read More

What is the difference between C++0x and C++11?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 586 Views

C++ and C Standards are usually named after the year they are published in. For example, in C++, the original Standard was published in 1998, so it is called C++98, and its first correction, published in 2003 is called C++03.For the next revision, it was supposed that the next Standard after would be done by 2008, but since it was uncertain, it was named C++0x, where the x stood for either 8 or 9. Though planning shifted and it is now called C++11. So, C++0x was the name for the standard before it was published. Once it was finalized in ...

Read More

Do you think a Python dictionary is thread safe?

George John
George John
Updated on 30-Jul-2019 2K+ Views

Yes, a Python dictionary is thread safe. Actually, all built-ins in python are thread safe. You can read moreabout this in the documentation: https://docs.python.org/3/glossary.html#term-global-interpreter-lock

Read More

Why accessing an array out of bounds does not give any error in C++?

Rishi Rathor
Rishi Rathor
Updated on 30-Jul-2019 2K+ Views

This is due to the fact that C++ does not do bounds checking. Languages like Java and python have bounds checking so if you try to access an out of bounds element, they throw an error. C++ design principle was that it shouldn't be slower than the equivalent C code, and C doesn't do array bounds checking.So if you try to access this out of bounds memory, the behavior of your program is undefined as this is written in the C++ standard. In general, whenever you encounter undefined behavior, anything might happen. The application may crash, it may freeze, it ...

Read More

How to create a Python dictionary from text file?

Jayashree
Jayashree
Updated on 30-Jul-2019 13K+ Views

Assuming a following text file (dict.txt) is present1 aaa2 bbb3 cccFollowing Python code reads the file using open() function. Each line as string is split at space character. First component is used as key and second as valued = {} with open("dict.txt") as f: for line in f:     (key, val) = line.split()     d[int(key)] = val print (d)The output shows contents of file in dictionary form{1: 'aaa', 2: 'bbb', 3: 'ccc'}

Read More

What is possible key/value delimiter in Python dictionary?

Chandu yadav
Chandu yadav
Updated on 30-Jul-2019 530 Views

You can use any hashable object like int, string, etc as a key in a python dict. You need to separate it from the value using the ':' delimiter. The value can be any type of object. Consecutive key value pairs must be separated by a comma.

Read More

What are the differences between struct and class in C++?

Ramu Prasad
Ramu Prasad
Updated on 30-Jul-2019 424 Views

The members and base classes of a struct are public by default, while in class, they default to private. Struct and class are otherwise functionally equivalent.They are however used in different places due to semantics. a struct is more like a data structure that is used to represent data. class, on the other hand, is more of a functionality inclined construct. It mimics the way things are and work.

Read More

How do Python dictionary hash lookups work?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 493 Views

Dicts are hash tables. No tree searching is used. Looking up a key is a nearly constant time(Amortized constant) operation, regardless of the size of the dict. It creates the hash of the key, then proceeds to find the location associated with the hashed value. If a collision listed address is encountered, it starts the collision resolution algorithm to find the actual value.This causes dictionaries to take up more space as they are sparse.

Read More

Difference between 'struct' and 'typedef struct' in C++?

Ankith Reddy
Ankith Reddy
Updated on 30-Jul-2019 956 Views

In C++, there is no difference between 'struct' and 'typedef struct' because, in C++, all struct/union/enum/class declarations act like they are implicitly typedef'ed, as long as the name is not hidden by another declaration with the same name.Though there is one subtle difference that typedefs cannot be forward declared. So for the typedef option, you must include the file containing the typedef before it is used anywhere.

Read More

How to optimize Python Dictionary for performance?

Samual Sam
Samual Sam
Updated on 30-Jul-2019 812 Views

dicts in python are heavily optimized. Creating a dict from N keys or key/value pairs is O(N), fetching is O(1), putting is amortized O(1), and so forth. You don't need to optimize them explicitly. You can be sure of this as python under the hood implements its own classes using dicts.Don't compare lists/tuples to dicts/sets though as they solve different problems.

Read More
Showing 25311–25320 of 25,467 articles
Advertisements