Saturday, March 19, 2022

Difference between C and C++ programmming language.





Difference Between C and C ++ programming language.

C Programming language


C was developed by Dennis Ritchie between the year 1969 and 1973 at AT&T Bell Labs.

C is a subset of C++. C contains 32 keywords. C++ contains 63 keywords.

For the development of code, C supports procedural programming. Functions in C are not defined inside structures. Namespace features are not present inside the C.Header file used by C is stdio.h. Virtual and friend functions are not supported by C.

C ++ Programming language

C++ was developed by Bjarne Stroustrup in 1979.

C++ is a superset of C . C++ is known as a hybrid language because C++ supports both procedural and object-oriented programming paradigms.C++ is an object-driven language. C++ focuses on data instead of focusing on method or procedure. C++ structures have access modifiers.C++ provides a new operator for memory allocation and a delete operator for memory de-allocation. Functions can be used inside a structure in C++. Namespace is used by C++, which avoids name collisions.

C is a very simple language actually, lacking many features found in newer languages. With C, there is no hand-holding, and most things have to be done manually. The standard library is very limited by modern standards. C is quite close to the hardware, which is actually its best feature. Being simple and close to the hardware is probably the main reason for C's continued success and popularity.

On the other hand, C++ is one of the more complex languages, which means it can take a long time to truly master. It evolved out of C, and therefore includes everything which was already in C. But, many C-style techniques are generally discouraged in C++. This combined with the fact that C++ is still evolving (C++11, 14) means that to master C++ you need to understand the history of the language and the advantages/disadvantages of different techniques. With C++ you can write high-performance, high-quality modular software. But there are many many pitfalls along the way, especially for those coming from a background of more forgiving languages (Java, C#, JavaScript, Python, etc.).

Most people don't realize that C++ can often produce even faster natively-compiled software than plain C. This is because of the template system and the ability to do extra work at compile time (for example, plain C's qsort is usually much slower than C++'s std::sort because of function pointers [C] vs. inlining [C++]). On the plus side, if you really master C++ most other languages will seem like a piece of cake by comparison.

C is a language invented between 1969–1973 along with the Unix OS, which was written in it. C++ was invented in 1979 and standardized in 1998, and it's basically a massive upgrade of C, but it's not C, it's something totally different altogether. Almost all code written in C will also compile perfectly as C++ code, since C++ is a strict superset of C, meaning it only adds features and doesn't remove or change anything (thus breaking compatibility).

Some of the additions are:

  • Classes, the main new feature. Basically structs with function members, inheritance, and access specifiers. In C++, structs are almost synonyms with classes, except they have public members and inheritance by default.
  • Namespaces, is also a big addition. In C, every function goes to a global namespace, which made name clashes common. Let's say you have included <unistd.h>: POSIX names are stupidly and dangerously generic, so you can't create a function called, for example, “open”.
  • Function overloading is also a big addition. C++ uses name mangling to store the function's name, which is used to differentiate functions of different parameter types.
  • Operator overloading, I wasn't kidding when I said it's massive, still a big addition, allows you to define custom behaviors for operations on classes. Syntax sugar, but welcome.
  • Lambdas (C++11 and up), an amendment for the fact neither C nor C++ have first-class functions. Basically, functions that can be defined inline, stored on a variable, passed around, and called.
  • Using statement, both a replacement for typedef and a way to use a namespace without typing its name all the time.
  • Constexpr variables and functions, are evaluated at compile-time, and can replace the preprocessor at times (but not always).


C and C++ are not the same there is a lot of difference between C and C++ languages.
  • C is a structural or procedural-oriented programming language but C++ is a partially object-oriented programming language.
  • In C++, We can use STL(Standard Template Library) to implement most of the Algorithms and Data Structures but in C we have to manually code everything.
  • In C++, there is a concept called the “Inline” function. The inline function execution is faster than the normal function. C doesn’t have the inline function concept.
  • In C++, We have the “Vectors” dynamically grow-able array but that is not possible in the c programming language.
  • We can implement all the C Programming concepts in C++ but vice versa is not possible.
  • In C++ by using the friend function we can access the private members of the class but there is no concept of classes in C++.
  • As C++ supports object-orientated programming we can implement Polymorphism, Inheritance, Abstraction, and Encapsulation but these are not possible in C language.

Friday, March 18, 2022

How to learn coding?


 

If you are reading this post then you definitely come here to know how to learn coding in this post, I will share my personal experience about it, how to learn to code.

Here are the steps 

STEP 1:

You should first of all try to pick up a programming language and learn it and try to understand its basic syntax and semantics. for a better understanding of concepts take C-language as your first language!

learn all the basics of language step by step and master all the basic concepts

Here are some basic concepts 

  • data types(int,char,float ,double etc.
  • operators(assignment,bitwise,logical etc.)
  • control statements(while loop,for loop,switch,continue,goto etc.)
  • structures
  • arrays
  • input/output
  • file handling
  • function
  • pointers

For learning languages, you can prefer many free online resources like 

  • Youtube lectures of mysirg.com, Code with harry, and many more.
  • W3School
  • Free Code Map
  • Geeks for geeks
  • Tutorial Points
  • Code Academy
  • Coding Chef
  • Stack Overflow
  • Github
  • You can refer to Udemy, Coursera for paid courses that have more content.

STEP 2 :

After learning c language try to solve questions on different concepts like

1. Basic maths

  • Addition, subtraction, etc.
  • Calculator, matrix manipulation, series,
  • Loop patterns,odd-even,sets,finding greatest number etc.

2. Arrays, and function, pointers based program

  • Array manipulation(finding greatest,sorting,adding,etc)
  • Basic program using function(call by value/reference)
  • Pointers manipulation and structure using pointers and all the possible stuff.

3. After you find yourself able to solve basic problems of programming of your own then try to learn

Data structures

  • Arrays
  • Linked lists
  • Rees
  • Hashing
  • Stack/queue implementation

Algorithms

  • Time complexity
  • Sorting techniques
  • Dynamic programming
  • Backtracking

4. Try to learn at least one or more object-oriented languages like c++, python, java.

STEP 3.

If you find yourself comfortable in coding basics then switch yourself to the world of competitive programming where your code and compete with masters/expert coders all over the world and try to take part in challenges held almost every week or month there are many competitive programming sites.

Suggesting one of our best for you.

  1. Hackerrank
  2. Codechef
  3. Codeforces
  4. HackerRank
  5. CodeChef
  6. Exercism.io
  7. Codewars
  8. LeetCode

Other suggestions we will provide are :

  • Research by yourself
  • Read programming & coding books
  • Do experiments with whatever you have learned
  • Play coding games
  • Look for new strategies
  • Develop your own
Happy Coding 

Thanks For reading 👀

Thursday, March 17, 2022

What is a Blockchain?


blockchain
Blockchains are incredibly popular nowadays, everyone is talking about it. You might be wondering why is it in trending these days. 

To understand the logic, let's see the following questions :-

  • What is a blockchain?
  • How does it work?
  • What problems it solves?
  • How it can be used?
Like the name indicates, a blockchain is a chain of blocks that contains information. This technique was originally described in 1991 by a group of researchers and was originally intended to timestamp digital documents so that it’s not possible to backdate them or to tamper with them. Almost like a notary. However, it went by mostly unused until it was adapted by Satoshi Nakamoto in 2009 to create the digital cryptocurrency Bitcoin.

A blockchain is a distributed ledger that is completely open to anyone. They have an interesting property: once some data has been recorded inside a blockchain, it becomes very difficult to change it.

How does it work?

Well, let’s take a closer look at a block.

Blocks

Each block contains some data, the hash of the block and the hash of the previous block.The data that is stored inside a block depends on the type of blockchain.

The Bitcoin blockchain for example stores the details about a transaction in here, such as the sender, receiver and amount of coins. A block also has a hash. You can compare a hash to a fingerprint. It identifies a block and all of its contents and it's always unique, just as a fingerprint. Once a block is created, it’s hash is being calculated. Changing something inside the block will cause the hash to change. So in other words: hashes are very useful when you want to detect changes to blocks. If the fingerprint of a block changes, it no longer is the same block. The third element inside each block is the hash of the previous block.This effectively creates a chain of blocks and it’s this technique that makes a blockchain so secure.


Let's take an example.
Three Blocks

Here we have a chain of 3 blocks. As you can see, each block has a hash and the hash of the previous block. So block number 3 points to block number 2 and number 2 points to number 1.

Now the first block is a bit special, it cannot point to previous blocks because it's the first one. We call this the genesis block. 

Now let's say that you tamper with the second block. This causes the hash of the block to change as well.

Blocks
Blocks

In turn that will make block 3 and all following blocks invalid because they no longer store a valid hash of the previous block. So changing a single block will make all following blocks invalid. But using hashes is not enough to prevent tampering.Computers these days are very fast and can calculate hundreds of thousands of hashes per second. You could effectively tamper with a block and recalculate all the hashes of other blocks to make your blockchain valid again.

So to mitigate this, blockchains have something called proof-of-work. It's a mechanism that slows down the creation of new blocks.

In Bitcoins case: it takes about 10 minutes to calculate the required Proof-of-work and add a new block to the chain.

Proof of work

This mechanism makes it very hard to tamper with the blocks, because if you tamper with 1 block, you'll need to recalculate the proof-of-work for all the following blocks. So the security of a blockchain comes from its creative use of hashing and the Proof-of-work (PoW) mechanism.


But there is one more way that blockchains secure themselves and that's by being distributed.

peer to peer
Peer to Peer

Instead of using a central entity to manage the chain, blockchains use a Peer-to-Peer network and anyone is allowed to join. When someone joins this network, he gets the full copy of the blockchain. The node can use this to verify that everything is still in order. Now let's see what happens when someone creates a new block. That new block is send to everyone on the network. Each node then verifies the block to make sure that it hasn't been tampered with. If everything checks out, each node adds this block to their own blockchain. All the nodes in this network create consensus. They agree about what blocks are valid and which aren't. Blocks that are tampered with will be rejected by other nodes in the network.

So to successfully tamper with a blockchain you'll need to tamper with all blocks on the chain, redo the proof-of-work for each block and take control of more than 50% of the peer-to-peer network. Only then will your tampered block become accepted by everyone else.

This is almost impossible to do! .Blockchains are also constantly evolving. One of the more recent developments is the creation of Smart contract.

Smart Contract
Smart Contract

These contracts are simple programs that are stored on the blockchain and can be used to automatically exchange coins based on certain conditions. More on smart contracts in another post. The creation of blockchain technology peaked a lot of people’s interest.

Soon, others realized that the technology could be used for other things like storing medical records, creating a digital notary or even collecting taxes.

Popular Posts

Mobile Phones News

Digital Trends