Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

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, January 20, 2022

C Programming - Tutorial


C Programming Tutorial

What is Programming?

Computer programming is a medium for us to communicate with computers, just like we use Hindi or English to communicate with each other. Programming is a way for us to deliver our instructions to the computer

What is C programming?

C is a programming language. C is one of the oldest and finest programming languages. C was developed by Dennis Ritchie in 1972.

Uses of C

C is a language that is used to program a wide variety of systems. Some of the uses of C are as follows:

Major parts of Windows, Linux, and other operating systems are written in C.
C is used to write driver programs for devices like Tablets, Printers, etc.
C language is used to program embedded systems where programs need to run faster in limited memory.
C is used to develop games, an area where latency is very important, i.e., a computer has to react quickly to user input.

Chapter 1: Variables, Constants, and Keywords:

Variables

A variable is a container that stores a ‘value.’ In the kitchen, we have containers storing rice, dal, sugar, etc. Similar to that variable in c stores the value of a constant. Example:

a = 3a is assigned “3”
b = 4.7b is assigned “4.7”
c = 'A'c is assigned “A”

Rules for naming variables in C :

1. The first character must be an alphabet or underscore(_).


2. No commas or blanks are allowed.

3. No special symbol other than underscore is allowed

4. Variable names are case sensitive


Constants

An entity whose value doesn’t change is called a constant.
Types of constant

Primarily there are 3 types of constant:

1. Integer Constant-1,6,7,9
2. Real Constant-322.1,2.5,7.0
3. Character Constant‘a’,’$’,’@’(must be enclosed within single inverted commas)

Keywords

These are reserved words whose meaning is already known to the compiler. There are 32 keywords available in C programming:

autodoubleintstruct
breaklongelse switch
casereturn enumtypedef
charregisterexternunion
constshortfloatunsigned
continuesignedforvoid
defaultsizeofgotovolatile
dostaticif while


Our first C program

#include<stdio.h>

int main() {

printf(“Hello World”);
return 0;

}

File : first.c

The basic structure of a C program

All c programs have to follow a basic structure. A c program starts with the main function and executes instructions presents inside it. Each instruction terminated with a semicolon(;)

There are some basic rules which are applicable to all the c programs:

  1. Every program's execution starts from the main function.
  2. All the statements are terminated with a semi-colon.
  3. Instructions are case-sensitive.
  4. Instructions are executed in the same order in which they are written.

Comments

Comments are used to clarify something about the program in plain language. It is a way for us to add notes to our program. There are two types of comments in c:
  1. Single line comment: //This is a comment.
  2. Multi-line comment : /*This is multi-line comment*/

Note: Comments in a C program are not executed and ignored.

Compilation and execution

A compiler is a computer program that converts a c program into machine language so that it can be easily understood by the computer.

A program is written in plain text. This plain text is a combination of instructions in a particular sequence. The compiler performs some basic checks and finally converts the program into an executable.

Library functions

C language has a lot of valuable library functions which is used to carry out a certain task; for instance, printf function is used to print values on the screen.

Types of variables

Integer variablesint a=3;
Real variablesint a=7.7 (wrong as 7.7 is real) ; float a=7.7;
Character variableschar a=’B’;

Chapter 2: Instructions and Operators:

A C-program is a set of instructions. Just like a recipe - which contains instructions to prepare a particular dish.

Types of instructions in C:

1. Type declaration instruction
2. Arithmetic instruction
3. Control instruction

Type of declaration instruction:

int a;
float b;

other variations:

int i = 10; int j = i, int a = 2;
int j1 = a + j - i;

float b = a+3; float a = 1.1; ==>Error! As we are trying to use a before defining it.

int a,b,c,d;

a=b=c=d=30; ==> Value of a,b,c & d will be 30 each.


Arithmetic Instructions



Note:
1.No operator is assumed to be present

int i=ab ( Invalid )
int i=a*b ( valid )

2. There is no operator to perform exponentiation in c however we can use pow(x,y) from <math.h> (More in next chapter).

Type conversion

An Arithmetic operation between

int and int ==> int
int and float ==> float
float and float ==> float

5/2 --> 2 5.0/2 --> 2.5 //IMPORTANT!!
2/5 --> 0 2.0/5 --> 0.4 //IMPORTANT!!

NOTE:
int a = 3.5; //In this case, 3.5 (float) will be denoted to a 3 (int) because a cannot store floats.

float a = 8; // a will store 8.0 [8-->8.0(Promotion to float)]

Quick Quiz:

Question - int k=3.0/9 value of k? and why?

Solution - 3.0/9=0.333, but since k is an int, it cannot store floats & value 0.33 is demoted to 0.

Operator Precedence in C

3*x-8y is (3x)-(8y) or 3(x-8y)?

In the c language, simple mathematical rules like BODMAS no longer apply.

The answer to the above question is provided by operator precedence & associativity.

Operator precedence

The following table list the operator priority in C.

PriorityOperators
1st  * / %
2nd+   -
3rd=

Operators of higher priority are evaluated first in the absence of parenthesis.

Sunday, August 22, 2021

What is an API | Application programming Interface


API


When you hang around programmers, you might have heard about APIs and how they can be
used to perform certain tasks or retrieve some data ,But what are these exactly, and why were they created?

Let me explain the problem with a simple, non-IT related example.



When you go to a restaurant and order some food, you interact with the waiter. You can order food and drinks, ask questions about the menu, request and pay the bill, and much more.

In this example, the waiter is shielding you from all the complicated stuff that happens
behind the scenes. you don’t have to worry about stoves, ovens, dishes, managing stock, or pouring drinks.

He is the interface between you and all of the services that a restaurant offers. Giving you a way to interact with the restaurant while still shielding you from all the complexity behind the scenes. In a way, the waiter can be seen as the API of the restaurant, and through this example, you intuitively understand why they are useful.

The term API stands for Application Programmable Interface, and it’s a way for different programs to work together in various ways. There are many types of API’s and reasons why they are used.

I’ll highlight 4 of them here:


For starters, API’s can be used to get access to data from third parties. In the restaurant example, the waiter can provide you information on the status of your order, without you having to go to the kitchen yourself. 

Another example would be the weather app on your phone. Google or Apple have not gone out and put temperature sensors all over the world. No, instead these apps use the API of a third-party to retrieve weather predictions. Apple for instance is using the API of The Weather Channel.

API’s allow different apps and services to exchange information. These days, it’s hard to find a service that doesn’t have an API. There are API’s to lookup recipes, lyrics, information on barcodes, zip codes, available parking spaces, public holidays, and so on and so on.

Aside from just accessing data, API's can also be used to hide complexity and perform tasks.

In the restaurant example, you don’t need to know how to prepare a perfect roll of Sushi,
you just order one. 

Another example would be the operating systems on our computers and phones. App developers don’t have to worry about setting up a WiFi connection, drawing shapes onto the screen to make a beautiful user interface or how to talk to the various sensors like the accelerometer or GPS.

No, instead the operating system gives developers a bunch of API’s that simplify all of this. If an app wants to show a button on the screen, it just asks the system to render one. The app doesn’t have to worry about what device it is running on, what hardware it has, screen resolution, or anything like that.
It makes developers more efficient because they can focus on what matters to them.

But aside from accessing data and abstracting complexity, API's can also be used to extend
functionality. For instance, on iOS, applications can show a widget in Notification Center.
And to do that, the app notifies the system through an API that it has a widget available.
And if the user adds it to their Notification Center, the system will contact the app to
ask how it should display the widget.

Another example is Siri, Google Assistant or Alexa. These personal assistants are quite clever but external developers can use the assistant’s API to extend the functionalities even further.

Google Home


My Google Home for instance didn’t know how to turn my smart plugs on and off.
But that changed, when the vendor integrated with the Google Assistant through its API.
Suddenly, Google became aware of the new hardware, its capabilities and how to interact with
them.

You might not realize it, but API’s are all around us. You’ve probably seen messages like these, your phone asking for permission to use your location or microphone. That brings us to the final use case: API’s can be used as gatekeepers.

For instance, on mobile platforms, the system only has a handful of API’s that can be
used to get your location. And because it’s centralized in the system, it’s really easy for iOS or Android to notify you when an app is using your location. So it’s not the app that is being nice, and asks permission first. No, it’s the system that does it for them.
There’s no way around it. What’s more, the system also gives the ability to revoke this permission at a later time, should you change your mind.

Phone Permission

So every time your phone asks you for permission, you know that an app is using an API of the
system. And one that is privacy sensitive. And while that is great, there is an issue with this usually permission is only asked once
.
You might have used your Google or Facebook account to login to another website or app.
It’s easy, fast and convenient. But by doing that, we also give the website or app the permission to access some of our data. Like our name or email address.

This is great, because it puts us in control of our personal data. if you don’t want to share it, you just deny it. However, the problem here is that sometimes these permissions are long lasting and after
a while we forget what apps or websites we gave permission to access our data. This is what allowed Cambridge Analytica to collect massive amounts of data through the Facebook API.

They created a “personality quiz” that asked for permission to get some of your personal
data. However, if you gave it permission, the app could silently access your data for months,
even if you didn’t use it anymore.

Instead, you had to revoke the permission through the Facebook website. So, in short: API’s can act as gatekeepers, protecting our personal data and only giving it out to the apps we choose.

But we should be aware about how long those permissions last, and revoke them when we
no longer use an app. So time for a conclusion. API’s are all around us.They are used to get access to data so that multiple apps or services can work together.They can also hide complexity for developers, allowing them to not waste time on figuring out how GPS works for instance.

API’s can also be used to extend functionality of existing systems and finally, they can
act as gatekeepers to protect our personal data.

I hope this article brought some clarity to a topic that is mostly discussed among developers.

Popular Posts

Mobile Phones News

Digital Trends