assignment of computer language

What is a programming language?

At its core, a programming language is a set of instructions that enables humans to communicate with computers—using a series of symbols that serve as a bridge that allows humans to turn our ideas into instructions computers can understand. Like spoken languages, each language has its own unique syntax, structure, vocabulary, and even slang or shortcuts.

In the vast digital landscape, programming languages are the “lingua francas” of software development, facilitating global conversations between machines and developers, wherever they may be. Their importance extends far beyond lines of code—they empower us to use technology to innovate, automate, and bring our imagination to life.

If you've ever wondered how your favorite apps, websites, or software come to life, you're in the right place. In this article, we'll explore the not-so-basic basics of programming languages, their pivotal role in software development, and how they shape the technological landscape we navigate daily.

What is the role of programming languages in software development?

A computer "speaks" in a "language" using strings of the numerals "1" and "0"—known as binary code. A programming language allows us to translate the computer's binary code into something humans can understand and write.

These languages enable us to communicate with computers, build and organize code, specify functionality and behavior, automate and improve efficiency, collaborate and share code, and solve problems creatively.

Here are some examples of how specific programming languages can help you to:

Communicate with computers:

Example: Python

Python is widely used for writing scripts and programs to communicate instructions to computers. For instance, a Python script can automate file operations, manage system tasks, or control hardware components, allowing developers to interact with computers at a low level.

Build and organize code:

Example: Java

Java is known for its object-oriented programming paradigm, making it suitable for building large-scale  enterprise applications.  Developers use Java to organize code into classes and modules, promoting code reusability and maintainability. The language's structure helps in creating well-organized and structured software projects.

Specify functionality and behavior:

Example: JavaScript

JavaScript is commonly used to specify the functionality and behavior of web applications. It runs in web browsers, allowing developers to define how web pages interact with users. JavaScript is essential for client-side scripting, enabling dynamic and interactive web experiences.

Automate and boost efficiency:

Example: Bash (Bourne Again Shell)

Bash scripting is used for automating repetitive tasks in the Linux environment. Developers write bash scripts to automate system tasks, file operations, and other routine processes. This enhances efficiency by reducing manual intervention in day-to-day operations.

Collaborate and code share:

Example: Ruby

Ruby on Rails is a web development framework that facilitates collaboration and sharing of code. It follows the convention over configuration (CoC) and don't repeat yourself (DRY) principles, making it easier for developers to work together on a project. The framework's structure encourages uniformity, easing collaboration among team members.

Adaptability and flexibility:

Example: C++

C++ is known for its adaptability and flexibility, allowing developers to write both low-level and high-level code. It is used in a variety of applications, from system programming to game development. C++ balances performance and abstraction, making it adaptable to different domains and requirements.

Problem solving and creativity:

Example: Python (again)

Python is mentioned twice with good reason—not only one of the most popular languages for beginners to learn, but it's also used for problem-solving and creative tasks due to its clear syntax and extensive libraries. Whether it's data analysis, machine learning, or building web apps, Python's versatility allows developers to approach problem-solving in creative ways. Its readability and expressiveness contribute to a more intuitive and creative coding experience.

How do programming languages work?

Programming languages are used in all areas of the  software development lifecycle (SDLC) , including:

Writing the code : Everything starts with code. Developers write lines of instructions, expressing their logic and intentions in a programming language, using a text editor or an integrated development environment (IDE).

Compilation vs. interpretation : Once code is written, it undergoes either compilation or interpretation, depending on the type of programming language used Compiled languages like C++ convert the entire code into machine-readable binary before execution. Interpreted languages like Python translate code line by line during runtime.

Execution : The compiled or interpreted code is executed by the computer, carrying out the specified instructions and producing the desired output. Code review helps to improve code quality and promote discussion among team members.

Runtime errors : During execution, some instructions may get "lost in translation." Runtime errors can range from logical mistakes in the code to unforeseen issues. Debugging becomes the detective work of identifying and fixing these errors.

Debugging : Debugging is the process of finding and resolving errors in code. Developers use  code review tools  and techniques to trace issues, ensuring the software behaves as intended, as well as to reduce security risks.

Types of programming languages

The most common types of programming languages can be broadly grouped into two families: paradigm-based and application-based.

Paradigm-based languages

Paradigm-based languages are classified based on their programming paradigm, which is a fundamental style of programming. Some examples of paradigm-based languages:

Imperative languages: are designed to express the sequence of steps required to solve a problem. They describe how a program operates using statements that change a program's state. Examples include C, C++, and Java.

Functional languages : Functional languages are designed to express computations as the evaluation of mathematical functions. They emphasize the use of functions and avoid changing state and mutable data. Examples include Haskell, Lisp, Scala, and ML.

Markup languages : Markup languages are designed to annotate text with metadata and are used often in web development to format and present text. Examples include HTML, XML, and LaTeX.

Application-based Languages

Application-based languages are classified based on their application domain. Some examples of application-based languages are:

Web development languages are vital for creating interactive and visually appealing websites and web applications. Examples include HTML, CSS, JavaScript, and PHP.

Mobile app development languages are tailored for building applications on mobile platforms. Examples include Java, Kotlin, and Swift.

Data science languages are designed for statistical analysis, machine learning, and data manipulation. Examples include Python, R, and SQL.

Popular programming languages

Programming languages may wax or wane in popularity—new languages are constantly being developed as new technologies emerge. If you're trying to decide which language to start your coding journey with or which one to use in a new project, check out the  Popularity of Programming Language (PYPL) index  which uses "collective wisdom" to indicate a language's current popularity by analyzing raw data from Google Trends.

Several programming languages are consistently found at the top of any popularity list:

Python : A high-level, general-purpose programming language widely used for web development, data science, artificial intelligence, and automation.

Strengths : Readability, versatility, and extensive libraries.

Weaknesses : Slower execution speed in comparison to lower-level languages.

JavaScript : JavaScript is known for its ability to enable interactive and dynamic content and user interfaces. It supports both client-side and server-side scripting.

Strengths : Ubiquitous in web development, asynchronous programming.

Weaknesses : Single-threaded nature, potential for browser compatibility issues.

Java : An object-oriented, statically typed, and compiled programming language renowned for its portability and platform independence. Java is particularly useful for apps in industries such as finance, healthcare, and entertainment and for Android, web, and  enterprise application development .

Strengths : Platform independence, strong community support.

Weaknesses : Verbosity, slower execution compared to lower-level languages.

C++ : A high-performance, object-oriented language that is used in system programming and scientific computing as well as used to develop operating systems, browsers, and games.

Strengths : High performance, extensive library support.

Weaknesses : Steeper learning curve, manual memory management.

C# : An object-oriented programming language that is used to develop Windows apps and games.

Strengths : Versatile and integrates efficiently with Visual Studio, .NET framework, and Microsoft Azure.

Weaknesses : Steeper learning curve and community size not as large as other popular languages like Java or Python.

Go : A statically typed, compiled programming language that is designed for building scalable and efficient software.

Strengths : Simplicity, concurrency support, and fast compilation.

Weaknesses : Smaller ecosystem compared to established languages.

Other popular programming languages include C, PHP, TypeScript, HTML, and CSS. C is a general-purpose, procedural programming language that is used to develop operating systems, device drivers, and embedded systems. PHP is a server-side scripting language that is used to create dynamic web pages, while TypeScript is a superset of JavaScript that adds optional static typing and other features to the language. HTML and CSS are markup languages that are used to create web pages.

assignment of computer language

GitHub’s DevOps Solution

Learn why 90% of the Fortune 100 use GitHub to build, scale, and deliver secure software. Start your journey with GitHub

How to learn programming languages

With the rise of generative AI tools like  GitHub Copilot  and  AI code generation , the language of coding has entered our common vocabulary—no matter your chosen profession or field. While large tech companies may seem like the pinnacle of coding achievement, they represent a small fraction of programming languages' impact. Many recruitment professionals predict that soon having a basic understanding of coding will be just as common and just as important as literacy or learning a foreign language. Learning a new programming language opens up numerous opportunities for career advancement.

Here are some steps to help you decide which programming language is best for you to learn:

1. Identify your purpose

Deciding which programming language to learn depends on what you want to do. Some languages, like Python or Java have huge communities of support, are easy to learn and use, and can be used for multiple applications. Others are more niche and designed to perform very specific tasks.

2. Choose a language

Based on your goals, select a language that aligns with your purpose. Python is often recommended for beginners due to its readability and versatility. Check out the resources with  GitHub Learning Pathways  to explore topics relevant to your goals.

3. Online courses and tutorials

Many platforms like Codecademy, Coursera, and Udacity offer interactive courses for various programming languages. Check out the video series,  Python for Beginners , from Microsoft Learn

4. Ebooks and documentations

Explore well-regarded ebooks on programming languages and refer to official documentation and resources of industry leaders like  GitHub  and  Microsoft Learn .

5. Practice and play around

Apply your knowledge by working on real-world projects. Platforms like GitHub provide a welcoming space to collaborate, showcase, and ask practical language questions.

6. Engage with communities of learners

Join online forums and communities to seek help, share experiences, and connect with other learners and experts. Get to know the community and learn what other developers are doing with your chosen language.

Get Started with programming languages

To sum up, programming languages allow us to instruct computers to build platforms for games and play, connect communities physically and virtually, and even create programs that provide life-saving medical interventions.

These languages are not only used by professional developers at big tech companies or Silicon Valley. Self-taught coders across diverse fields such as science, gaming, sports, finance, and healthcare are continually learning new languages. Becoming fluent in a programming language (or several!) is an essential tool in software development. Whether you're a seasoned developer or a curious beginner, learning a new programming language will spark inventive ways to use technology and translates into "happy coding" in any language!

More resources to get started

Write more code by writing less code with GitHub Copilot >

Empowering developers to build secure software faster >

Frequently asked questions

Why are programming languages important in software development.

Programming languages are the foundation of software development. They are used to write instructions that computers can understand and execute. Programming languages are important because they allow developers to create software that can solve complex problems, automate tasks, and improve efficiency. Different programming languages are suited for different types of app development—and these languages are just the useful tools used to envision and build their ideas.

How many programming languages are there?

That may be a trick question! New languages are being developed so quickly—it may not be possible to know an exact total number and it really depends on the source you consult. If you're asking about all languages that have ever existed, some claim the number is over 8,945 historical programming languages. If you just want to know which are in current use, the estimates are around 700 languages. However, only a handful of programming languages are widely used today.

There are certainly a lot of programming languages out there, but most software engineers build a satisfying career by mastering a few of the most popular coding languages.

What is an example of a programming language?

Some of the most popular programming languages include:

Python : A high-level language that is easy to learn and widely used for data analysis and machine learning.

Java : A versatile language that is used for developing mobile apps, web applications, and enterprise software.

JavaScript : A scripting language that is used for creating interactive web pages and web apps.

C++ : A powerful language with applications in system programming, game development, and high-performance apps.

What is the difference between programming and coding?

Coding is the act of writing code, while programming is the process of creating the instructions that code follows.

What is a coding language? Is a coding language the same thing as a programming language?

While the terms coding and programming are often used interchangeably, they don't quite mean the same thing.  Coding  refers to the process of writing code in a language that both humans and machines can understand.  Programming  is the process of creating code instructions that tell a computer how to perform a specific task. A  programming language  is a formal language that specifies a set of instructions for a computer to perform specific tasks. Programming languages are used to write software programs and applications, and to control and manipulate computer systems.

Explore Software Engineering

Delve into the world of software engineering: understand its principles, the role of engineers, and how it shapes the development of reliable, efficient software.

Dive into Software Development

Discover the basics of software development, key concepts, and its impact on industries. A complete guide for beginners to navigate the tech landscape.

Discover Open Source Software

Unveil the world of Open Source Software (OSS): its benefits, community-driven development model, and how it fosters innovation and collaboration.

Browse Course Material

Course info, instructors.

  • Prof. Eric Grimson
  • Prof. John Guttag

Departments

  • Electrical Engineering and Computer Science

As Taught In

  • Programming Languages

Introduction to Computer Science and Programming

Assignments.

facebook

You are leaving MIT OpenCourseWare

If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

To log in and use all the features of Khan Academy, please enable JavaScript in your browser.

Computer programming - JavaScript and the web

Unit 1: intro to js: drawing & animation, unit 2: intro to html/css: making webpages, unit 3: intro to sql: querying and managing data, unit 4: advanced js: games & visualizations, unit 5: advanced js: natural simulations, unit 6: html/js: making webpages interactive, unit 7: html/js: making webpages interactive with jquery, unit 8: meet the professional, browse projects.

The C Programming Handbook for Beginners

Dionysia Lemonaki

C is one of the oldest, most widely known, and most influential programming languages.

It is used in many industries because it is a highly flexible and powerful language.

Learning C is a worthwhile endeavor – no matter your starting point or aspirations – because it builds a solid foundation in the skills you will need for the rest of your programming career.

It helps you understand how a computer works underneath the hood, such as how it stores and retrieves information and what the internal architecture looks like.

With that said, C can be a difficult language to learn, especially for beginners, as it can be cryptic.

This handbook aims to teach you C programming fundamentals and is written with the beginner programmer in mind.

There are no prerequisites, and no previous knowledge of any programming concepts is assumed.

If you have never programmed before and are a complete beginner, you have come to the right place.

Here is what you are going to learn in this handbook:

Chapter 1: Introduction to C Programming

  • Chapter 2: Variables and Data Types in C
  • Chapter 3: Operators in C
  • Chapter 4: Conditional Statements in C
  • Chapter 5: Loops in C
  • Chapter 6: Arrays in C
  • Chapter 7: Strings in C

Further learning: Advanced C Topics

Without further ado, let’s get started with learning C!

In this introductory chapter, you will learn the main characteristics and use cases of the C programming language.

You will also learn the basics of C syntax and familiarize yourself with the general structure of all C programs.

By the end of the chapter, you will have set up a development environment for C programming so you can follow along with the coding examples in this book on your local machine.

You will have successfully written, compiled, and executed your first simple C program that prints the text "Hello, world!" to the screen.

You will have also learned some core C language features, such as comments for documenting and explaining your code and escape sequences for representing nonprintable characters in text.

What Is Programming?

Computers are not that smart.

Even though they can process data tirelessly and can perform operations at a very high speed, they cannot think for themselves. They need someone to tell them what to do next.

Humans tell computers what to do and exactly how to do it by giving them detailed and step-by-step instructions to follow.

A collection of detailed instructions is known as a program.

Programming is the process of writing the collection of instructions that a computer can understand and execute to perform a specific task and solve a particular problem.

A programming language is used to write the instructions.

And the humans who write the instructions and supply them to the computer are known as programmers.

Low-level VS High-Level VS Middle-level Programming Languages – What's The Difference?

There are three types of programming languages: low-level languages, high-level languages, and middle-level languages.

Low-level languages include machine language (also known as binary) and assembly language.

Both languages provide little to no abstraction from the computer's hardware. The language instructions are closely related to or correspond directly to specific machine instructions.

This 'closeness to the machine' allows for speed, efficiency, less consumption of memory, and fine-grained control over the computer's hardware.

Machine language is the lowest level of programming languages.

The instructions consist of series of 0 s and 1 s that correspond directly to a particular computer’s instructions and locations memory.

Instructions are also directly executed by the computer’s processor.

Even though machine language was the language of choice for writing programs in the early days of computing, it is not a human-readable language and is time-consuming to write.

Assembly language allows the programmer to work closely with the machine on a slightly higher level.

It uses mnemonics and symbols that correspond directly to a particular machine’s instruction set instead of using sequences of 0 s and 1 s.

Next, high-level languages, like Python and JavaScript, are far removed from the instruction set of a particular machine architecture.

Their syntax resembles the English language, making them easier to work with and understand.

Programs written in high-level languages are also portable and machine-independent. That is, a program can run on any system that supports that language.

With that said, they tend to be slower, consume more memory, and make it harder to work with low-level hardware and systems because of how abstract they are.

Lastly, middle-level languages, like C and C++, act as a bridge between low-level and high-level programming languages.

They allow for closeness and a level of control over computer hardware. At the same time, they also offer a level of abstraction with instructions that are more human-readable and understandable for programmers to write.

What Is the C Programming Language?

C is a general-purpose and procedural programming language.

A procedural language is a type of programming language that follows a step-by-step approach to solving a problem.

It uses a series of instructions, otherwise known as procedures or functions, that are executed in a specific order to perform tasks and accomplish goals. These intructions tell the computer step by step what to do and in what order.

So, C programs are divided into smaller, more specific functions that accomplish a certain task and get executed sequentially, one after another, following a top-down approach.

This promotes code readability and maintainability.

A Brief History of the C Programming Language

C was developed in the early 1970s by Dennis Ritchie at AT&T Bell Laboratories.

The development of C was closely tied to the development of the Unix operating system at Bell Labs.

Historically, operating systems were typically written in Assembly language and without portability in mind.

During the development of Unix, there was a need for a more efficient and portable programming language for writing operating systems.

Dennis Ritchie went on to create a language called B, which was an evolution from an earlier language called BCPL (Basic Combined Programming Language).

It aimed to bridge the gap between the low-level capabilities of Assembly and the high-level languages used at the time, such as Fortran.

B was not powerful enough to support Unix development, so Dennis Ritchie developed a new language that took inspiration from B and BCPL and had some additional features. He named this language C.

C’s simple design, speed, efficiency, performance, and close relationship with a computer’s hardware made it an attractive choice for systems programming. This led to the Unix operating system being rewritten in C.

C Language Characteristics and Use Cases

Despite C being a relatively old language (compared to other, more modern, programming languages in use today), it has stood the test of time and still remains popular.

According to the TIOBE index , which measures the popularity of programming languages each month, C is the second most popular programming language as of August 2023.

This is because C is considered the "mother of programming languages" and is one of the most foundational languages of computer science.

Most modern and popular languages used today either use C under the hood or are inspired by it.

For example, Python’s default implementation and interpreter, CPython, is written in C. And languages such as C++ and C# are extensions of C and provide additional functionality.

Even though C was originally designed with systems programming in mind, it is widely used in many other areas of computing.

C programs are portable and easy to implement, meaning they can be executed across different platforms with minimal changes.

C also allows for efficient and direct memory manipulation and management, making it an ideal language for performance-critical applications.

And C provides higher-level abstractions along with low-level capabilities, which allows programmers to have fine-grained control over hardware resources when they need to.

These characteristics make C an ideal language for creating operating systems, embedded systems, system utilities, Internet of things (IoT) devices, database systems, and various other applications.

C is used pretty much everywhere today.

How to Set Up a Development Environment for C Programming on Your Local Machine

To start writing C programs on your local machine, you will need the following:

  • A C Compiler
  • An Integrated Development Environment (IDE)

C is a compiled programming language, like Go, Java, Swift, and Rust.

Compiled languages are different from interpeted languages, such as PHP, Ruby, Python, and JavaScript.

The difference between compiled and interpeted languages is that a compiled language is directly translated to machine code all at once.

This process is done by a special program called a compiler.

The compiler reads the entire source code, checks it for errors, and then translates the entire program into machine code. This is a language the computer can understand and it's directly associated with the particular instructions of the computer.

This process creates a standalone binary executable file containing sequences of 0 s and 1 s which is a more computer-friendly form of the initial source code. This file contains instructions that the computer can understand and run directly.

An interpeted language, on the other hand, doesn’t get translated into machine code all at once and doesn’t produce a binary executable file.

Instead, an interpreter reads and executes the source code one instruction at a time, line by line. The interpreter reads each line, translates it into machine code, and then immediately runs it.

If you are using a Unix or a Unix-like system such as macOS or Linux, you probably have the popular GNU Compiler Collection (GCC) already installed on your machine.

If you are running either of those operating systems, open the terminal application and type the following command:

If you're using macOS and have not installed the command line developer tools, a dialog box will pop-up asking you to install them – so if you see that, go ahead and do so.

If you have already installed the command line tools, you will see an output with the version of the compiler, which will look similar to the following:

If you are using Windows, you can check out Code::Blocks or look into installing Linux on Windows with WSL . Feel free to pick whatever programming environment works best for you.

An IDE is where you write, edit, save, run, and debug your C programs. You can think of it like a word processor but for writing code.

Visual Studio Code is a great editor for writing code, and offers many IDE-like features.

It is free, open-source, supports many programming languages, and is available for all operating systems.

Once you have downloaded Visual Studio Code, install the C/C++ extension .

It’s also a good idea to enable auto-saving by selecting: "File" -> "Auto Save".

If you want to learn more, you can look through the Visual Studio Code documentation for C/C++ .

With your local machine all set up, you are ready to write your first C program!

How to Write Your First C Program

To get started, open Visual Studio Code and create a new folder for your C program by navigating to "File" -> "Open" -> "New Folder".

Give this folder a name, for example, c-practice , and then select "Create" -> “Open".

You should now have the c-practice folder open in Visual Studio Code.

Inside the folder you just created, create a new C file.

Hold down the Command key and press N on macOS or hold down the Control and press N for Windows/Linux to create an Untitled-1 file.

Hold down the Command key and press S on macOS or hold down the Control key and press S for Windows/Linux, and save the file as a main.c file.

Finally, click "Save".

Make sure that you save the file you created with a .c extension, or it won’t be a valid C file.

You should now have the main.c file you just created open in Visual Studio Code.

Next, add the following code:

Let’s go over each line and explain what is happening in the program.

What Are Header Files in C?

Let’s start with the first line, #include <stdio.h> .

The #include part of #include <stdio.h> is a preprocessor command that tells the C compiler to include a file.

Specifically, it tells the compiler to include the stdio.h header file.

Header files are external libraries.

This means that some developers have written some functionality and features that are not included at the core of the C language.

By adding header files to your code, you get additional functionality that you can use in your programs without having to write the code from scratch.

The stdio.h header file stands for standard input-output.

It contains function definitions for input and output operations, such as functions for gathering user data and printing data to the console.

Specifically, it provides functions such as printf() and scanf() .

So, this line is necessary for the function we have later on in our program, printf() , to work.

If you don't include the stdio.h file at the top of your code, the compiler will not understand what the printf() function is.

What is the main() function in C?

Next, int main(void) {} is the main function and starting point of every C program.

It is the first thing that is called when the program is executed.

Every C program must include a main() function.

The int keyword in int main(void) {} indicates the return value of the main() function.

In this case, the function will return an integer number.

And the void keyword inside the main() function indicates that the function receives no arguments.

Anything inside the curly braces, {} , is considered the body of the function – here is where you include the code you want to write. Any code written here will always run first.

This line acts as a boilerplate and starting point for all C programs. It lets the computer know where to begin reading the code when it executes your programs.

What Are Comments in C?

In C programming, comments are lines of text that get ignored by the compiler.

Writing comments is a way to provide additional information and describe the logic, purpose, and functionality of your code.

Comments provide a way to document your code and make it more readable and understandable for anyone who will read and work with it.

Having comments in your source code is also helpful for your future self. So when you come back to the code in a few months and don't remember how the code works, these comments can help.

Comments are also helpful for debugging and troubleshooting. You can temporarily comment out lines of code to isolate problems.

This will allow you to ignore a section of code and concentrate on the piece of code you are testing and working on without having to delete anything.

There are two types of comments in C:

  • Single-line comments
  • Multi-line comments

Single-line comments start with two forward slashes, // , and continue until the end of the line.

Here is the syntax for creating a single-line comment in C:

Any text written after the forward slashes and on the same line gets ignored by the compiler.

Multi-line comments start with a forward slash, / , followed by an asterisk, * , and end with an asterisk, followed by a forward slash.

As the name suggests, they span multiple lines.

They offer a way to write slightly longer explanations or notes within your code and explain in more detail how it works.

Here is the syntax for creating a multi-line comment in C:

What is the printf() function in C?

Inside the function's body, the line printf("Hello, World!\n"); prints the text Hello, World! to the console (this text is also known as a string).

Whenever you want to display something, use the printf() function.

Surround the text you want to display in double quotation marks, "" , and make sure it is inside the parentheses of the printf() function.

The semicolon, ; , terminates the statement. All statements need to end with a semicolon in C, as it identifies the end of the statement.

You can think of a semicolon similar to how a full stop/period ends a sentence.

What Are Escape Sequences in C?

Did you notice the \n at the end of printf("Hello, World!\n"); ?

It's called an escape sequence, which means that it is a character that creates a newline and tells the cursor to move to the next line when it sees it.

In programming, an escape sequence is a combination of characters that represents a special character within a string.

They provide a way to include special characters that are difficult to represent directly in a string.

They consist of a backslash, \ , also known as the escape character, followed by one or more additional characters.

The escape sequence for a newline character is \n .

Another escape sequence is \t . The \t represrents a tab character, and will insert a space within a string.

How to Compile and Run Your first C Program

In the previous section, you wrote your first C program:

Any code you write in the C programming language is called source code.

Your computer doesn’t understand any of the C statements you have written, so this source code needs to be translated into a different format that the computer can understand. Here is where the compiler you installed earlier comes in handy.

The compiler will read the program and translate it into a format closer to the computer’s native language and make your program suitable for execution.

You will be able to see the output of your program, which should be Hello, world! .

The compilation of a C program consists of four steps: preprocessing, compilation, assembling, and linking.

The first step is preprocessing.

The preprocessor scans through the source code to find preprocessor directives, which are any lines that start with a # symbol, such as #include .

Once the preprocessor finds these lines, it substitutes them with something else.

For example, when the preprocessor finds the line #include <stdio.h> , the #include tells the preprocessor to include all the code from the stdio.h header file.

So, it replaces the #include <stdio.h> line with the actual contents of the stdio.h file.

The output of this phase is a modified version of the source code.

After preprocessing, the next step is the compilation phase, where the modified source code gets translated into the corresponding assembly code.

If there are any errors, compilation will fail, and you will need to fix the errors to continue.

The next step is the assembly phase, where the assembler converts the generated assembly code statements into machine code instructions.

The output of this phase is an object file, which contains the machine code instructions.

The last step is the linking phase.

Linking is the process of combining the object file generated from the assembly phase with any necessary libraries to create the final executable binary file.

Now, let’s go over the commands you need to enter to compile your main.c file.

In Visual Studio Code, open the built-in terminal by selecting "Terminal" -> "New Terminal".

Inside the terminal, enter the following command:

The gcc part of the command refers to the C compiler, and main.c is the file that contains the C code that you want to compile.

Next, enter the following command:

The ls command lists the contents of the current directory.

The output of this command shows an a.out file – this is the executable file containing the source code statements in their corresponding binary instructions.

The a.out is the default name of the executable file created during the compilation process.

To run this file, enter the following command:

This command tells the computer to look in the current directory, ./ , for a file named a.out .

The above command generates the following output:

You also have the option to name the executable file instead of leaving it with the default a.out name.

Say you wanted to name the executable file helloWorld .

If you wanted to do this, you would need to enter the following command:

This command with the -o option (which stands for output) tells the gcc compiler to create an executable file named helloWorld .

To run the new executable file that you just created, enter the following command:

This is the output of the above command:

Note that whenever you make a change to your source code file, you have to repeat the process of compiling and running your program from the beginning to see the changes you made.

Chapter 2: Variables and Data Types

In this chapter, you will learn the basics of variables and data types – the fundamental storage units that allow you to preserve and manipulate data in your programs.

By the end of this chapter, you will know how to declare and initialize variables.

You will also have learned about various data types available in C, such as integers, floating-point numbers, and characters, which dictate how information is processed and stored within a program's memory.

Finally, you'll have learned how to receive user input in your programs, and how to use constants to store values that you don't want to be changed.

What Is a Variable in C?

Variables store different kind of data in the computer's memory, and take up a certain amount of space.

By storing information in a variable, you can retrieve and manipule it, perform various calculations, or even use it to make decisions in your program.

The stored data is given a name, and that is how you are able to access it when you need it.

How to Declare Variables in C

Before you can use a variable, you need to declare it – this step lets the compiler know that it should allocate some memory for it.

C is a strongly typed language, so to declare a variable in C, you first need to specify the type of data the variable will hold, such as an integer to store a whole number, a floating-point number for numbers with decimal places, or a char for a single character.

That way, during compilation time, the compiler knows if the variable is able to perform the actions it was set out to do.

Once you have specified the data type, you give the variable a name.

The general syntax for declaring variables looks something like this:

Let's take the following example:

In the example above, I declared a variable named age that will hold integer values.

What Are the Naming Conventions for Variables in C?

When it comes to variable names, they must begin either with a letter or an underscore.

For example, age and _age are valid variable names.

Also, they can contain any uppercase or lowercase letters, numbers, or an underscore character. There can be no other special symbols besides an underscore.

Lastly, variable names are case-sensitive. For example, age is different from Age .

How to Initialize Variables in C

Once you've declared a variable, it is a good practice to intialize it, which involves assigning an initial value to the variable.

The general syntax for initialzing a variable looks like this:

The assignment operator, = , is used to assign the value to the variable_name .

Let's take the previous example and assign age a value:

I initialized the variable age by assigning it an integer value of 29 .

With that said, you can combine the initialization and declaration steps instead of performing them separately:

How to Update Variable Values in C

The values of variables can change.

For example, you can change the value of age without having to specify its type again.

Here is how you would change its value from 29 to 30 :

Note that the data type of the new value being assigned must match the declared data type of the variable.

If it doesn't, the program will not run as expected. The compiler will raise an error during compilation time.

What Are the Basic Data Types in C?

Data types specify the type of form that information can have in C programs. And they determine what kind of operations can be performed on that information.

There are various built-in data types in C such as char , int , and float .

Each of the data types requires different allocation of memory.

Before exploring each one in more detail, let’s first go over the difference between signed and unsigned data types in C.

Signed data types can represent both positive and negative values.

On the other hand, unsigned data types can represent only non-negative values (zero and positive values).

Wondering when to use signed and when to use unsigned data types?

Use signed data types when you need to represent both positive and negative values, such as when working with numbers that can have positive and negative variations.

And use unsigned data types when you want to ensure that a variable can only hold non-negative values, such as when dealing with quantities.

Now, let's look at C data types in more detail.

What Is the char Data Type in C?

The most basic data type in C is char .

It stands for "character" and it is one of the simplest and most fundamental data types in the C programming language.

You use it to store a single individual character such as an uppercase and lowercase letter of the ASCII (American Standard Code for Information Interchange) chart.

Some examples of char s are 'a' and 'Z' .

It can also store symbols such as '!' , and digits such as '7' .

Here is an example of how to create a variable that will hold a char value:

Notice how I used single quotation marks around the single character.

This is because you can't use double quotes when working with char s.

Double quotes are used for strings.

Regarding memory allocation, a signed char lets you store numbers ranging from [-128 to 127 ], and uses at least 1 byte (or 8 bits) of memory.

An unsigned char stores numbers ranging from [0 to 255] .

What Is the int Data Type in C?

An int is a an integer, which is also known as a whole number.

It can hold a positive or negative value or 0 , but it can't hold numbers that contain decimal points (like 3.5 ).

Some examples of integers are 0 , -3 ,and 9 .

Here is how you create a variable that will hold an int value:

When you declare an int , the computer allocates at least 2 bytes (or 16 bits) of memory.

With that said, on most modern systems, an int typically allocates 4 bytes (or 32 bits) of memory.

The range of available numbers for a signed int is [-32,768 to 32,767] when it takes up 2 bytes and [-2,147,483,648 to 2,147,483,647] when it takes up 4 bytes of memory.

The range of numbers for an unsigned int doesn't include any of the negative numbers in the range mentioned for signed int s.

So, the range of numbers for unsigned ints that take up 2 bytes of memory is [0 to 65,535] and the range is [0 to 4,294,967,295] for those that take up 4 bytes.

To represent smaller numbers, you can use another data type – the short int . It typically takes up 2 bytes (or 16 bits) of memory.

A signed short int allows for numbers in a range from [-32,768 to 32,767] .

An unsigned short int allows for numbers in a range from [0 to 65,535] .

Use a short when you want to work with smaller integers, or when memory optimisation is critically important.

If you need to work with larger integers, you can also use other data types like long int or long long int , which provide a larger range and higher precision.

A long int typically takes up at least 4 bytes of memory (or 32 bits).

The values for a signed long int range from [-2,147,483,648 to 2,147,483,647] .

And the values for an unsigned long int range from [0 to 4,294,967,295] .

The long long int data type is able to use even larger numbers than a long int . It usually takes up 8 bytes (or 64 bits) of memory.

A signed long long int allows for a range from [-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807]

And an unsigned long long int has a range of numbers from [0 to 18,446,744,073,709,551,615] .

What Is The float Data Type in C?

The float data type is used to hold numbers with a decimal value (which are also known as real numbers).

It holds 4 bytes (or 32 bits) of memory and it is a single-precision floating-point type.

Here is how you create a variable that will hold a float value:

A double is a floating point value and is the most commonly used floating-point data type in C.

It holds 8 bytes (or 64 bits) of memory, and it is a double-precision floating-point type.

Here is how you create a variable that will hold a double value:

When choosing which floating-point data type to use, consider the trade-off between memory usage and precision.

A float has less precision that a double but consumes less memory.

Use a float when memory usage is a concern (such as when working with a system with limited resources) or when you need to perform calculations where high precision is not critical.

If you require higher precision and accuracy for your calculations and memory usage is not critical, you can use a double .

What Are Format Codes in C?

Format codes are used in input and output functions, such as scanf() and printf() , respectively.

They act as placeholders and substitutes for variables.

Specifically, they specify the expected format of input and output.

They tell the program how to format or interpret the data being passed to or read from the scanf() and printf() functions.

The syntax for format codes is the % character and the format specifier for the data type of the variable.

In the example above, age is the variable in the program. It is of type int .

The format code – or placeholder – for integer values is %i . This indicates that an integer should be printed.

In the program's output, %i is replaced with the value of age , which is 29 .

Here is a table with the format specifiers for each data type:

FORMAT SPECIFIER DATA TYPE
%c char
%c unsigned char
%i, &d int
%u unsigned int
%hi, %hd short int
%hu unsigned short int
%li or %ld long int
%lu unsigned long int
%lli or %lld long long int
%llu unsigned long long int
%f float
%lf double
%Lf long double

How to Recieve User Input Using the scanf() Function

Earlier you saw how to print something to the console using the printf() function.

But what happens when you want to receive user input? This is where the scanf() function comes in.

The scanf() function reads user input, which is typically entered via a keyboard.

The user enters a value, presses the Enter key, and the value is saved in a variable.

The general syntax for using scanf() looks something similar to the following:

Let's break it down:

  • format_string is the string that lets the computer know what to expect. It specifies the expected format of the input. For example, is it a word, a number, or something else?
  • &variable is the pointer to the variable where you want to store the value gathered from the user input.

Let's take a look at an example of scanf() in action:

In the example above, I first have to include the stdio.h header file, which provides input and output functions in C.

Then, in the main() function, I declare a variable named number that will hold integer values. This variable will store the user input.

Then, I prompt the user to enter a number using the printf() function.

Next, I use scanf() to read and save the value that the user enters.

The format specifier %i lets the computer known that it should expect an integer input.

Note also the & symbol before the variable name. Forgetting to add it will cause an error.

Lastly, after receiving the input, I display the received value to the console using another printf() function.

What are Constants in C?

As you saw earlier on, variable values can be changed throughout the life of a program.

With that said, there may be times when you don’t want a value to be changed. This is where constants come in handy.

In C, a constant is a variable with a value that cannot be changed after declaration and during the program's execution.

You can create a constant in a similar way to how you create variables.

The differences between constants and variables is that with constants you have to use the const keyword before mentioning the data type.

And when working with constants, you should always specify a value.

The general syntax for declaring constants in C looks like this:

Here, data_type represents the data type of the constant, constant_name is the name you choose for the constant, and value is the value of the constant.

It is also best practice to use all upper case letters when declaring a constant’s name.

Let’s see an example of how to create a constant in C:

In this example, LUCKY_NUM is defined as a constant with a value of 7 .

The constant's name, LUCKY_NUM , is in uppercase letters, as this is a best practice and convention that improves the readability of your code and distinguishes constants from variables.

Once defined, it cannot be modified in the program.

If you try to change its value, the C compiler will generate an error indicating that you are attempting to modify a constant.

Chapter 3: Operators

Operators are essential building blocks in all programming languages.

They let you perform various operations on variables and values using symbols.

And they let you compare variables and values against each other for decision-making computatons.

In this chapter, you will learn about the most common operators in C programming.

You will first learn about arithmetic operators, which allow you to perform basic mathematical calculations.

You will then learn about relational (also known as comparisson operators), which help you compare values.

And you will learn about logical operators, which allow you to make decisions based on conditions.

After understanding these fundamental operators, you'll learn about some additional operators, such as assignment operators, and increment and decrement operators.

By the end of this chapter, you will have a solid grasp of how to use different operators to manipulate data.

What Are the Arithmetic Operators in C?

Arithmetic operators are used to perform basic arithmetic operations on numeric data types.

Operations include addition, subtraction, multiplication, division, and calculating the remainder after division.

These are the main arithmetic operators in C:

Operator Operation
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder after division (modulo)

Let's see examples of each one in action.

How to Use the Addition ( + ) Operator

The addition operator adds two operands together and returns their sum.

How to Use the Subtraction ( - ) Operator

The subtraction operator subtracts the second operand from the first operand and returns their difference.

How to Use the Multiplication ( * ) Operator

The multiplication operator multiplies two operands and returns their product.

How to Use the Division ( / ) Operator

The division operator divides the first operand by the second operand and returns their quotient.

How to Use the Modulo ( % ) Operator

The modulo operator returns the remainder of the first operand when divided by the second operand.

The modulo operator is commonly used to determine whether an integer is even or odd.

If the remainder of the operation is 1 , then the integer is odd. If there is no remainder, then the integer is even.

What Are The Relational Operators in C?

Relational operators are used to compare values and return a result.

The result is a Boolean value. A Boolean value is either true (represented by 1 ) or false (represented by 0 ).

These operators are commonly used in decision-making statements such as if statements, and while loops.

These are the relational operators in C:

Operator Name of Operator
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to

Let’s see an example of each one in action.

How to Use the Equal to ( == ) Operator

The equal to operator checks if two values are equal.

It essentially asks the question, "Are these two values equal?"

Note that you use the comparisson operator (two equal signs – == ) and not the assignment operator ( = ) which is used for assigning a value to a variable.

The result is 1 (true), because a and b are equal.

How to Use the Not equal to ( != ) Operator

The not equal to operator checks if two values are NOT equal.

The result is 1 (true), because a and b are not equal.

How to Use the Greater than ( > ) Operator

This operator compares two values to check if one is greater than the other.

The result is 1 (true), because a is greater than b .

How to Use the Less than ( < ) Operator

This operator compares two values to check if one is less than the other.

The result is 0 (false), because a is not less than b .

How to Use the Greater than or Equal to ( >= ) Operator

This operator compares two values to check if one is greater than or equal to the other.

The result is 1 (true), because a is equal to b .

How to Use the Less than or equal to ( <= ) Operator

This operator compares two values to check if one is less than or equal the other.

The result is 1 (true), because a is less than b .

Logical Operators

Logical operators operate on Boolean values and return a Boolean value.

Here are the logical operators used in C:

Operator Name of Operator
Logical AND
Logical OR
Logical NOT

Let's go into more detail on each one in the following sections.

How to Use the AND ( && ) Operator

The logical AND ( && ) operator checks whether all operands are true .

The result is true only when all operands are true .

Here is the truth table for the AND ( && ) operator when you are working with two operands:

FIRST OPERAND SECOND OPERAND RESULT
true true true
true false false
false true false
false false false

The result of (10 == 10) && (20 == 20) is true because both operands are true .

Let's look at another example:

The result of (10 == 20) && (20 == 20) is false because one of the operands is false .

When the first operand is false , the second operand is not evaluated (since there's no point - it's already determined that the first operand is false, so the result can only be false ).

How to Use the OR ( || ) Operator

The logical OR ( || ) operator checks if at least one of the operands is true .

The result is true only when at least one of the operands is true .

Here is the truth table for the OR ( || ) operator when you are working with two operands:

FIRST OPERAND SECOND OPERAND RESULT
true true true
true false true
false true true
false false false

Let's look at an example:

The result of (10 == 20) || (20 == 20) is true because one of the operands is true .

The result of (20 == 20) || (10 == 20) is true because one of the operands is true

If the first operand is true , then the second operator is not evaluated.

How to Use the NOT ( ! ) Operator

The logical NOT ( ! ) operator negates the operand.

If the operand is true , it returns false .

And if it is false , it returns true .

You may want to use the NOT operator when when you want to flip the value of a condition and return the opposite of what the condition evaluates to.

Here is the truth table for the NOT( ! ) operator:

OPERAND RESULT
true false
false true

The result of !(10 == 10) is false .

The condition 10 == 10 is true , but the ! operator negates it so the result is false .

And let's look at another example:

The result of !(10 == 20) is true .

The condition 10 == 20 is false, but the ! operator negates it.

What Is the Assignement Operator in C?

The assignment operator is used to assign a value to a variable.

In the example above, the value 10 is assigned to the variable num using the assignment operator.

The assignment operator works by evaluating the expression on the right-hand side and then storing its result in the variable on the left-hand side.

The type of data assigned should match the data type of the variable.

How to Use Compound Assignment Operators

Compound assignment operators are shorthand notations.

They allow you to modify a variable by performing an operation on it and then storing the result of the operation back into the same variable in a single step.

This can make your code more concise and easier to read.

Some common compound assignment operators in C include:

  • += : Addition and assignment
  • = : Subtraction and assignment
  • = : Multiplication and assignment
  • /= : Division and assignment
  • %= : Modulo and assignment

Let’s see an example of how the += operator works:

In the example above, I created a variable named num and assigned it an initial value of 10 .

I then wanted to increment the variable by 5 . To do this, I used the += compound operator.

The line num += 5 increments the value of num by 5, and the result (15) is stored back into num in one step.

Note that the num += 5; line works exactly the same as doing num = num + 5 , which would mean num = 10 + 5 , but with fewer lines of code.

What Are the Increment and Decrement Operators in C?

The increment ++ and decrement -- operators increment and decrement a variable by one, respectively.

Let’s look at an example of how to use the ++ operator:

The initial value of the variable num is 10 .

By using the ++ increment operator, the value of num is set to 11 .

This is like perfoming num = num + 1 but with less code.

The shorthand for decrementing a variable by one is -- .

If you wanted to decrement num by one, you would do the following:

By using the -- increment operator, the value of num is now set to 9 . This is like perfoming num = num - 1 .

Chapter 4: Conditional Statements

The examples you have seen so far all execute line by line, from top to bottom.

They are not flexible and dynamic and do not adapt according to user behavior or specific situations.

In this chapter, you will learn how to make decisions and control the flow of a program.

You get to set the rules on what happens next in your programs by setting conditions using conditional statements.

Conditional statements take a specific action based on the result of a comparisson that takes place.

The program will decide what the next steps should be based on whether the conditions are met or not.

Certain parts of the program may not run depending on the results or depending on certain user input. The user can go down different paths depending on the various forks in the road that come up during a program's life.

First, you will learn about the if statement – the foundational building block of decision-making in C.

You will also learn about the else if and else statements that are added to the if statement to provide additional flexibility to the program.

You will then learn about the ternary operator which allows you to condense decision-making logic into a single line of code and improve the readability of your program.

How to Create an if statement in C

The most basic conditional statement in C is the if statement.

It makes a decision based on a condition.

If the given condition evaluates to true only then is the code inside the if block executed.

If the given condition evaluates to false , the code inside the if block is ignored and skipped.

The general syntax for an if statement in C is the following:

In the above code, I created a variable named age that holds an integer value.

I then prompted the user to enter their age and stored the answer in the variable age .

Then, I created a condition that checks whether the value contained in the variable age is less than 18.

If so, I want a message printed to the console letting the user know that to proceed, the user should be at least 18 years of age.

When asked for my age and I enter 16 , I'd get the following output:

The condition ( age < 18 ) evaluates to true so the code in the if block executes.

Then, I re-compile and re-run the program.

This time, when asked for my age, say I enter 28 , but I don't get any output:

This is because the condition evaluates to false and therefore the body of the if block is skipped.

I have also not specified what should happen in the case that the user's age is greater than 18.

To specify what happens in case the user's age is greater than 18, I can use an if else statement.

How to Create an if else statement in C

You can add an else clause to an if statement to provide code that will execute only when the if statement evaluates to false .

The if else statement essentially means that " if this condition is true do the following thing, else do this thing instead".

If the condition inside the parentheses evaluates to true , the code inside the if block will execute.

But if that condition evaluates to false , the code inside the else block will execute.

The else keyword is the solution for when the if condition is false and the code inside the if block doesn't run. It provides an alternative.

The general syntax looks like this:

Now, let's revisit the example from the previous section, and specify what should happen if the user's age is greater than 18:

If the condition is true the code in the if block runs:

If the condition is false the code in the if block is skipped and the code in the else block runs instead:

How to Create an else if statement in C

But what happens when you want to have more than one condition to choose from?

If you wish to chose between more than one option you can introduce an else if statement.

An else if statement essentially means that "If this condition is true, do the following. If it isn't, do this instead. However, if none of the above are true and all else fails, finally do this."

The general syntax looks something like the following:

Let's see how an else if statement works.

Say you have the following example:

If the first if statement is true, the rest of the block will not run:

If the first if statement is false, then the program moves on to the next condition.

If that is true the code inside the else if block executes and the rest of the block doesn't run:

If both of the previous conditions are all false, then the last resort is the else block which is the one to execute:

How to Use the Ternary Operator in C

The ternary operator (also known as the conditional operator) allows you to write an if else statement with fewer lines of code.

It can provide a way of writing more readable and concise code and comes in handy when writing simple conditional expressions.

You would want to use it when you are making making simple decisions and want to keep your code concise and on one line.

However, it's best to stick to a regular if-else statement when you are dealing with more complex decisions as the ternary operator could make your code hard to read.

The general syntax for the ternary operator looks something similar to the following:

  • condition is the condition you want to evaluate. This condition will evaluate to either true of false
  • ? separates the condition from the two possible expressions
  • expression_if_true is executed if the condition evaluates to true
  • : separates the expression_if_true from the expression_if_false
  • expression_if_false is executed if the condition evaluates to false .

Let's take a look at an example:

In the example above, the condition is (x > 5) .

If x is greater than 5, the condition evaluates to true . And when the condition is true , the value assigned to y will be 100 .

If the condition evaluates to false , the value assigned to y will be 200 .

So, since x is greater than 5 ( x = 10 ), y is assigned the value 100 .

Chapter 5: Loops

In this chapter you will learn about loops, which are essential for automating repetitive tasks without having to write the same code multiple times.

Loops allow you to execute a specific block of code instructions repeatedly over and over again until a certain condition is met.

You will learn about the different types of loops, such as the for , while and do-while loops, and understand their syntax and when you should use each one.

You will also learn about the break statement, which allows you to control the execution flow within loops in specific ways.

How to Create a for Loop in C

A for loop allows you to execute a block of code repeatedly based on a specified condition.

It's useful when you know how many times you want to repeat a certain action.

The general syntax for a for loop looks like this:

  • initialization is the step where you initialize a loop control variable. It's typically used to set the starting point for your loop.
  • condition is the condition that is evaluated before each iteration. If the condition is true , the loop continues. If it's false , the loop terminates. The loop will run as long as the condition remains true.
  • increment/decrement is the part responsible for changing the loop control variable after each iteration. It can be an increment ( ++ ), a decrement ( -- ), or any other modification.
  • Code to be executed in each iteration is the block of code inside the for loop's body that gets executed in each iteration if the condition is true .

Let's see an example of how a for loop works.

Say you want to print the numbers from 1 to 5 to the console:

In the example above, I first initialize the loop control variable i with a value of 1 .

The condition i <= 5 is true, so the loop's body is executed and "Iteration 1" is printed.

After each iteration, the value of i is incremented by 1 . So, i is incremented to 2 .

The condition is still true , so "Iteration 2" is printed.

The loop will continue as long as i is less than or equal to 5 .

When i becomes 6 , the condition evaluates to false and the loop terminates.

How to Create a while Loop in C

As you saw in the previous section, a for loop is used when you know the exact number of iterations you want the loop to perform.

The while loop is useful when you want to repeat an action based on a condition but don't know the exact number of iterations beforehand.

Here is the general syntax of a while loop:

With a while loop, the condition is evaluated before each iteration. If the condition is true , the loop continues. If it's false, the loop terminates.

The while loop will continue as long as the condition evaluates to true .

Something to note with while loops is that the code in the loop's body is not guaranteed to run even at least one time if a condition is not met.

Let's see an example of how a while loop works:

In the example above, I first initialize a variable count with a value of 1 .

Before it runs any code, the while loop checks a condition.

The condition count <= 5 is true because count is initially 1 . So, the loop's body is executed and "Iteration 1" is printed.

Then, count is incremented to 2 .

The loop will continue as long as count is less than or equal to 5.

This process continues until count becomes 6 , at which point the condition becomes false , and the loop terminates.

Something to be aware of when working with while loops is accidentally creating an infinite loop:

In this case the condition always evaluates to true .

After printing the line of code inside the curly braces, it continuously checks wether it should run the code again.

As the answer is always yes (since the condition it needs to check is always true each and every time), it runs the code again and again and again.

The way to stop the program and escape from the endless loop is running Ctrl C in the terminal.

How to Create a do-while Loop in C

As mentioned in the previous section, the code in the while loop's body is not guaranteed to run even at least one time if the condition is not met.

A do-while loop executes a block of code repeatedly for as long as a condition remains true .

However, in contrast to a while loop, it is guaranteed to run at least once, regardless of whether the condition is true or false from the beginning.

So, the do-while loop is useful when you want to ensure that the loop's body is executed at least once before the condition is checked.

The general syntax for a do-while loop looks like this:

Let's take a look at an example that demonstrates how a do-while loop works:

In the example above I initialize a variable count with a value of 1 .

A do-while loop first does something and then checks a condition.

So, the block of code inside the loop is executed at least one time.

The string "Iteration 1" is printed and then count is incremented to 2 .

The condition count <= 5 is then checked and it evaluates to true , so the loop continues.

After the iteration where count is 6 , the condition becomes false , and the loop terminates.

How to Use the break Statement in C

The break statement is used to immediately exit a loop and terminate its execution.

It's a control flow statement that allows you to interrupt the normal loop execution and move on to the code after the loop.

The break statement is especially useful when you want to exit a loop under specific conditions, even if the loop's termination condition hasn't been met.

You might use it when you encounter a certain value, or when a specific condition is met.

Here's how to use a break statement in a loop:

In the example above, a for loop is set to iterate from 1 to 10 .

Inside the loop, the current value of i is printed on each iteration.

There is also an if statement that checks if the current value of i matches the target value, which is set to 5 .

If i matches the target value, the if statement is triggered and a message is printed.

As a result, the break statement exits the current loop immediately and prematurely.

The program will continue executing the code that is after the loop.

Chapter 6: Arrays

Arrays offer a versatile and organized way to store multiple pieces of related data that are arranged in an ordered sequence.

They allow you to store multiple values of the same data type under a single identifier and perform repetitive tasks on each element.

In this chapter, you will learn how to declare and initialize arrays. You will also learn how to access individual elements within an array using index notation and modify them.

In addition, you will learn how to use loops to iterate through array elements and perform operations on each element.

How to Declare and Initialize an Array in C

To declare an array in C, you first specify the data type of the elements the array will store.

This means you can create arrays of type int , float , char , and so on.

You then specify the array's name, followed by the array's size in square brackets.

The size of the array is the number of elements that it can hold. This number must be a positive integer.

Keep in mind that arrays have a fixed size, and once declared, you cannot change it later on.

Here is the general syntax for declaring an array:

Here is how to declare an array of integers:

In the example above, I created an array named grades that can store 5 int numbers.

After declaring an array, you can initialize it with initial values.

To do this, use the assignment operator, = , followed by curly braces, {} .

The curly braces will enclose the values, and each value needs to be separated by a comma.

Here is how to initialize the grades array:

Keep in mind that the number of values should match the array size, otherwise you will encounter errors.

Something to note here is that you can also partially initialize the array:

In this case, the remaining two elements will be set to 0 .

Another way to initialize arrays is to omit the array's length inside the square brackets and only assign the initial values, like so:

In this example, the array's size is 5 because I assigned it 5 values.

How to Find the Length of an Array in C Using the sizeof() Operator

The sizeof operator comes in handy when you need to calculate the size of an array.

Let's see an example of the sizeof operator in action:

In the example above, sizeof(grades) calculates the total size of the array in bytes.

In this case, the array has five integers.

As mentioned in a previous chapter, on most modern systems an int typically occupies 4 bytes of memory. Therefore, the total size is 5 x 4 = 20 bytes of memory for the entire array.

Here is how you can check how much memory each int occupies using the sizeof operator:

The sizeof(grades[0]) calculates the size of a single element in bytes.

By dividing the total size of the array by the size of a single element, you can calculate the number of elements in the array, which is equal to the array's length:

How to Access Array Elements in C

You can access each element in an array by specifying its index or its position in the array.

Note that in C, indexing starts at 0 instead of 1 .

So, the index of the first element is 0 , the index of the second element is 1 , and so on.

The last element in an array has an index of array_size - 1 .

To access individual elements in the array, you specify the array's name followed by the element's index number inside square brackets ( [] ).

Let's take a look at the following example:

In the example above, to access each item from the integer array grades , I have to specify the array's name along with the item's position in the array inside square brackets.

Remember that the index starts from 0 , so grades[0] gives you the first element, grades[1] gives you the second element, and so on.

Note that if you try to access an element with an index number that is higher than array_size - 1 , the compiler will return a random number:

How to Modify Array Elements in C

Once you know how to access array elements, you can then modify them.

The general syntax for modifying an array element looks like this:

You can change the value of an element by assigning a new value to it using its index.

Let's take the grades array from earlier on:

Here is how you would change the value 75 to 85 :

When modifying arrays, keep in mind that the new value must match the declared data type of the array.

How to Loop Through an Array in C

By looping through an array, you can access and perform operations on each element sequentially.

The for loop is commonly used to iterate through arrays.

When using a for loop to loop through an array, you have to specify the index as the loop variable, and then use the index to access each array element.

The %i placeholders are replaced with the current index i and the value at that index in the grades array, respectively.

You can also use a while loop to iterate through an array:

When using a while loop to loop through an array, you will need an index variable, int i = 0 , to keep track of the current position in the array.

The loop checks the condition (i < 5) and prints the index of the grade as well as the actual grade value.

After each grade is shown, the variable i is increased by one, and the loop continues until it has shown all the grades in the list.

A do-while works in a similar way to the while loop, but it is useful when you want to ensure that the loop body is executed at least once before checking the condition:

You can also use the sizeof operator to loop through an array.

This method is particularly useful to ensure your loop doesn't exceed the array's length:

The line int length = sizeof(grades) / sizeof(grades[0]); calculates the length of the grades array.

The length is calculated by dividing the total size (in bytes) of the array by the size of a single element grades[0] . The result is stored in the length variable.

The loop then iterates through the array using this length value.

For each iteration, it prints the index i and the value of the grade at that index grades[i] .

Chapter 7: Strings

In the previous chapter, you learned the basics of arrays in C.

Now, it's time to learn about strings – a special kind of array.

Strings are everywhere in programming. They are used to represent names, messages, passwords, and more.

In this chapter, you will learn about strings in C and how they are stored as arrays of characters.

You'll also learn the fundamentals of string manipulation.

Specifically, you will learn how to find a string's length and how to copy, concatenate, and compare strings in C.

What Are Strings in C?

A string is a sequence of characters, like letters, numbers, or symbols, that are used to represent text.

In C, strings are actually arrays of characters. And each character in the string has a specific position within the array.

Another unique characteristic of strings in C is that at the end of every one, there is a hidden \0 character called the 'null terminator'.

This terminator lets the computer know where the string ends.

So, the string ' Hello ' in C is stored as ' Hello\0 ' in memory.

How to Create Strings in C

One way to create a string in C is to initialize an array of characters.

The array will contain the characters that make up the string.

Here is how you would initialize an array to create the string 'Hello':

Note how I specified that the array should store 6 characters despite Hello being only 5 characters long. This is due to the null operator.

Make sure to include the null terminator, \0 , as the last character to signify the end of the string.

Let's look at how you would create the string 'Hello world':

In this example, there is a space between the word 'Hello' and the word 'world'.

So, the array must include a blank space character.

To print the string, you use the printf() function, the %s format code and the name of the array:

Another way to create a string in C is to use a string literal.

In this case, you create an array of characters and then assign the string by enclosing it in double quotes:

With string literals, the null terminator ( \0 ) is implied.

Creating strings with string literals is easier, as you don't need to add the null terminator at the end. This method is also much more readable and requires less code.

However, you may want to use character arrays when you want to modify the string's content. String literals are read-only, meaning the content is fixed.

How to Manipulate Strings in C

C provides functions that allow you to perform operations on strings, such as copying, concatenating, and comparing, to name a few.

To use these functions, you first need to include the string.h header file by adding the line #include <string.h> at the top of your file.

How to Find the Length of a String in C

To calculate the length of a string, use the strlen() function:

The strlen() function will return the number of characters that make up the string.

Note that the result does not include the null terminator, \0 .

How to Copy a String in C

To copy one string into another one, you can use the strcpy() function.

You may want to copy a string in C when you need to make changes to it without modifying it. It comes in handy when you need to keep the original string's content intact.

The general syntax for the strcpy() function looks like this:

The strcpy() function copies original_string into destination_string , including the null terminator ( '\0' ).

One thing to note here is that you need to make sure the destination array has enough space for the original string:

The strcpy() function copies the original string into an empty array and returns the copied string, which also includes the null terminator character ( '\0' ).

How to Concatenate Strings in C

You can concatenate (add) two strings together by using the strcat() function.

The general syntax for the strcat() function looks something like the following:

The strcat() function takes the original string and adds it to the end of destination string.

Make sure that the destination_string has enough memory for the original_string .

Something to note here is that strcat() does not create a new string.

Instead, it modifies the original destination_string , by including the original_string at the end.

Let's see an example of how strcat() works:

How to Compare Strings in C

To compare two strings for equality, you can use the strcmp() function.

The general syntax for the strcmp() function looks like this:

The strcmp() function compares string1 with string2 and returns an integer.

If the return value of strcmp() is 0 , then it means the two strings are the same:

If the return value of strcmp() is less than 0 , then it means the first word comes before the second:

And if the return value of strcmp() is greater than 0 , then it means the first word comes after the second one:

While this handbook has covered a wide range of topics, there is still so much to learn, as programming is so vast.

Once you have built a solid foundation with the basics of C programming, you may want to explore more advanced concepts.

You may want to move on to learning about functions, for example. They allow you to write instructions for a specific task and reuse that code throughout your program.

You may also want to learn about pointers. Pointers in C are like arrows that show you where a specific piece of information is stored in the computer's memory.

Then, you may want to move on to learning about structures. They're like custom data containers that allow you to group different types of information under one name.

Lastly, you may want to learn how to work with files. Working with files in C allows you to read from and write to files. This is useful for tasks like saving user data, reading configuration settings, or sharing data between different programs.

These suggestions are not a definitive guide – just a few ideas for you to continue your C programming learning journey.

If you are interested in learning more, you can check out the following freeCodeCamp resources:

  • C Programming Tutorial for Beginners
  • Learn C Programming Using the Classic Book by Kernighan and Ritchie
  • Unlock the Mysteries of Pointers in C

This marks the end of this introduction to the C programming language.

Thank you so much for sticking with it and making it until the end.

You learned how to work with variables, various data types, and operators.

You also learned how to write conditional statements and loops. And you learned the basics of working with arrays and strings.

Hopefully, you have gained a good understanding of some of the fundamentals of C programming, got some inspiration on what to learn next, and are excited to continue your programming journey.

Happy coding!

Read more posts .

If this article was helpful, share it .

Learn to code for free. freeCodeCamp's open source curriculum has helped more than 40,000 people get jobs as developers. Get started

Logo for Rebus Press

Want to create or adapt books like this? Learn more about how Pressbooks supports open publishing practices.

Kenneth Leroy Busbee

An assignment statement sets and/or re-sets the value stored in the storage location(s) denoted by a variable name; in other words, it copies a value into the variable. [1]

The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within most programming languages the symbol used for assignment is the equal symbol. But bite your tongue, when you see the = symbol you need to start thinking: assignment. The assignment operator has two operands. The one to the left of the operator is usually an identifier name for a variable. The one to the right of the operator is a value.

Simple Assignment

The value 21 is moved to the memory location for the variable named: age. Another way to say it: age is assigned the value 21.

Assignment with an Expression

The item to the right of the assignment operator is an expression. The expression will be evaluated and the answer is 14. The value 14 would be assigned to the variable named: total_cousins.

Assignment with Identifier Names in the Expression

The expression to the right of the assignment operator contains some identifier names. The program would fetch the values stored in those variables; add them together and get a value of 44; then assign the 44 to the total_students variable.

  • cnx.org: Programming Fundamentals – A Modular Structured Approach using C++
  • Wikipedia: Assignment (computer science) ↵

Programming Fundamentals Copyright © 2018 by Kenneth Leroy Busbee is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License , except where otherwise noted.

Share This Book

Encyclopedia Britannica

  • Games & Quizzes
  • History & Society
  • Science & Tech
  • Biographies
  • Animals & Nature
  • Geography & Travel
  • Arts & Culture
  • On This Day
  • One Good Fact
  • New Articles
  • Lifestyles & Social Issues
  • Philosophy & Religion
  • Politics, Law & Government
  • World History
  • Health & Medicine
  • Browse Biographies
  • Birds, Reptiles & Other Vertebrates
  • Bugs, Mollusks & Other Invertebrates
  • Environment
  • Fossils & Geologic Time
  • Entertainment & Pop Culture
  • Sports & Recreation
  • Visual Arts
  • Demystified
  • Image Galleries
  • Infographics
  • Top Questions
  • Britannica Kids
  • Saving Earth
  • Space Next 50
  • Student Center
  • Introduction

Machine and assembly languages

  • Visual Basic
  • Declarative languages
  • Scripting languages
  • Web scripting
  • Control structures
  • Data structures

human trafficking

computer programming language

Our editors will review what you’ve submitted and determine whether to revise the article.

  • IEEE Computer Sociey - Coding From 1849 to 2022: a Guide to The Timeline of Programming Languages
  • Computer Science at Brown University - A History of Computer Programming Languages
  • Open Library Publishing Platform - Digital Humanities Tools and Techniques I - An introduction to and and overview of computer programming languages
  • Table Of Contents

computer programming language , any of various languages for expressing a set of detailed instructions for a digital computer . Such instructions can be executed directly when they are in the computer manufacturer-specific numerical form known as machine language , after a simple substitution process when expressed in a corresponding assembly language , or after translation from some “higher-level” language. Although there are many computer languages, relatively few are widely used.

Machine and assembly languages are “low-level,” requiring a programmer to manage explicitly all of a computer’s idiosyncratic features of data storage and operation. In contrast, high-level languages shield a programmer from worrying about such considerations and provide a notation that is more easily written and read by programmers.

Language types

A machine language consists of the numeric codes for the operations that a particular computer can execute directly. The codes are strings of 0s and 1s, or binary digits (“bits”), which are frequently converted both from and to hexadecimal (base 16) for human viewing and modification. Machine language instructions typically use some bits to represent operations, such as addition, and some to represent operands, or perhaps the location of the next instruction. Machine language is difficult to read and write, since it does not resemble conventional mathematical notation or human language, and its codes vary from computer to computer.

Assembly language is one level above machine language. It uses short mnemonic codes for instructions and allows the programmer to introduce names for blocks of memory that hold data. One might thus write “add pay, total” instead of “0110101100101000” for an instruction that adds two numbers.

computer chip. computer. Hand holding computer chip. Central processing unit (CPU). history and society, science and technology, microchip, microprocessor motherboard computer Circuit Board

Assembly language is designed to be easily translated into machine language. Although blocks of data may be referred to by name instead of by their machine addresses, assembly language does not provide more sophisticated means of organizing complex information. Like machine language, assembly language requires detailed knowledge of internal computer architecture . It is useful when such details are important, as in programming a computer to interact with peripheral devices (printers, scanners, storage devices, and so forth).

Algorithmic languages

Algorithmic languages are designed to express mathematical or symbolic computations. They can express algebraic operations in notation similar to mathematics and allow the use of subprograms that package commonly used operations for reuse. They were the first high-level languages.

The first important algorithmic language was FORTRAN ( for mula tran slation), designed in 1957 by an IBM team led by John Backus . It was intended for scientific computations with real numbers and collections of them organized as one- or multidimensional arrays. Its control structures included conditional IF statements, repetitive loops (so-called DO loops), and a GOTO statement that allowed nonsequential execution of program code. FORTRAN made it convenient to have subprograms for common mathematical operations, and built libraries of them.

FORTRAN was also designed to translate into efficient machine language. It was immediately successful and continues to evolve.

ALGOL ( algo rithmic l anguage) was designed by a committee of American and European computer scientists during 1958–60 for publishing algorithms , as well as for doing computations. Like LISP (described in the next section), ALGOL had recursive subprograms—procedures that could invoke themselves to solve a problem by reducing it to a smaller problem of the same kind. ALGOL introduced block structure, in which a program is composed of blocks that might contain both data and instructions and have the same structure as an entire program. Block structure became a powerful tool for building large programs out of small components.

ALGOL contributed a notation for describing the structure of a programming language, Backus–Naur Form, which in some variation became the standard tool for stating the syntax (grammar) of programming languages. ALGOL was widely used in Europe, and for many years it remained the language in which computer algorithms were published. Many important languages, such as Pascal and Ada (both described later), are its descendants.

The C programming language was developed in 1972 by Dennis Ritchie and Brian Kernighan at the AT&T Corporation for programming computer operating systems . Its capacity to structure data and programs through the composition of smaller units is comparable to that of ALGOL. It uses a compact notation and provides the programmer with the ability to operate with the addresses of data as well as with their values. This ability is important in systems programming , and C shares with assembly language the power to exploit all the features of a computer’s internal architecture. C, along with its descendant C++ , remains one of the most common languages.

Business-oriented languages

COBOL ( co mmon b usiness o riented l anguage) has been heavily used by businesses since its inception in 1959. A committee of computer manufacturers and users and U.S. government organizations established CODASYL ( Co mmittee on Da ta Sy stems and L anguages) to develop and oversee the language standard in order to ensure its portability across diverse systems.

COBOL uses an English-like notation—novel when introduced. Business computations organize and manipulate large quantities of data, and COBOL introduced the record data structure for such tasks. A record clusters heterogeneous data—such as a name, an ID number, an age, and an address—into a single unit. This contrasts with scientific languages, in which homogeneous arrays of numbers are common. Records are an important example of “chunking” data into a single object, and they appear in nearly all modern languages.

Popular Coding Symbols in Programming Languages self.__wrap_b=(t,n,e)=>{e=e||document.querySelector(`[data-br="${t}"]`);let a=e.parentElement,r=R=>e.style.maxWidth=R+"px";e.style.maxWidth="";let o=a.clientWidth,c=a.clientHeight,i=o/2-.25,l=o+.5,u;if(o){for(;i+1 {self.__wrap_b(0,+e.dataset.brr,e)})).observe(a):process.env.NODE_ENV==="development"&&console.warn("The browser you are using does not support the ResizeObserver API. Please consider add polyfill for this API to avoid potential layout shifts or upgrade your browser. Read more: https://github.com/shuding/react-wrap-balancer#browser-support-information"))};self.__wrap_b(":Rid9j6:",1)

Vishnupriya's profile image

Basic Symbols and Their Functions

Symbols for comparison and logic, assignment and special operators, advanced symbol usage, cross-language symbol comparison, best practices.

Popular Coding Symbols in Programming Languages

Welcome to the intricate world of coding symbols in programming languages! If you’re a coding enthusiast, a student, or a professional developer, you already know that coding is not just about typing commands; it’s about understanding the language of the computer. Symbols in programming are like the punctuation marks in a written language—they give structure, meaning, and clarity to our code. Whether you’re learning through platforms like codedamn or diving into documentation, a solid grasp of these symbols is crucial for efficient and error-free coding.

In this section, we’ll dive into the basic symbols that form the backbone of many programming languages. These symbols might seem small and insignificant, but they play a major role in how a program functions. Let’s explore some of these symbols and understand their importance.

Semicolon (;)

The semicolon is a critical symbol in many programming languages, including C, C++, and Java. It’s used to mark the end of a statement, much like a period in a sentence. This tells the compiler or interpreter where one statement ends and another begins, helping to avoid confusion and errors. For instance, in JavaScript, a semicolon is used to separate statements, although it’s often optional due to Automatic Semicolon Insertion (ASI). However, relying on ASI can sometimes lead to unexpected results, so it’s generally good practice to include semicolons explicitly.

Parentheses (())

Parentheses are used in virtually all programming languages, and their role can vary depending on the context. They are commonly used in function calls and definitions, where they enclose arguments or parameters. For example, print("Hello, World!") in Python uses parentheses to hold the string that the print function will output. They’re also crucial in controlling the order of operations in mathematical expressions, just like in algebra.

The plus symbol is most commonly associated with addition in mathematics, and this holds true in programming as well. In many languages like Python, Java, and JavaScript, the plus symbol is used for adding numbers. But its role doesn’t stop there. In languages like JavaScript, the plus symbol can also be used for string concatenation, meaning it can combine two strings into one. For instance, "Hello " + "World!" results in "Hello World!" . It’s a versatile symbol with multiple uses depending on the context.

Now, let’s turn our attention to symbols that are used for comparison and logical operations. These symbols are essential for making decisions in code and controlling the flow of execution based on certain conditions.

Equality (==) and Inequality (!=) Operators

Equality ( == ) and inequality ( != ) operators are fundamental in programming languages like JavaScript, Python, and many others. They are used to compare values. The equality operator ( == ) checks if the values on either side are equivalent, while the inequality operator ( != ) checks if they are not. It’s important to note that == in JavaScript does type coercion, which can lead to unexpected results. For strict comparison, === is used, which compares both value and type.

Logical And (&) and Or (||)

Logical operators such as And ( & ) and Or ( || ) play a pivotal role in decision-making in programming. They are used to combine multiple conditions. In a logical AND operation, the result is true if all conditions are true. In contrast, the logical OR operation yields true if at least one of the conditions is true. These operators are widely used in programming languages like C++, Java, and JavaScript for constructing complex logical expressions.

In the world of programming, understanding the significance and functionality of various symbols is crucial. These symbols, often compact and seemingly simple, carry a great deal of meaning and are fundamental in structuring and executing code effectively. In this section, we’ll dive into some of the commonly used assignment and special operators, exploring their roles and nuances across different programming languages.

Assignment Operator (=)

The assignment operator, represented by the equal sign = , is one of the most fundamental symbols in programming. It is used to assign values to variables. In most languages, the operator takes the value on its right and stores it in the variable on its left. For instance, x = 5 assigns the value 5 to the variable x . It’s essential to differentiate between the assignment operator and the equality operator (== in many languages), which is used for comparison.

Dollar Sign ($)

The dollar sign $ holds a special place in several programming languages, notably PHP. In PHP, the dollar sign is used to denote variables. For example, $username represents a variable named ‘username’. Its use simplifies the process of variable identification and differentiation from other elements in the code. This specific use of the dollar sign is unique to PHP and a few other languages, marking a distinctive syntax feature.

Braces ({})

Braces, or curly brackets {} , are versatile symbols used across various programming languages with multiple purposes. In languages like C, C++, and Java, braces define the scope of code blocks, encapsulating functions, loops, and conditional statements. They help in structuring the code, making it readable and maintainable. For instance, in a function definition, the code within the braces is the function body. Braces also play a significant role in object and array initializations in languages like JavaScript and Python.

As we delve deeper into programming, we encounter symbols that play more specialized roles, often pivotal in advanced coding techniques and structures. These symbols contribute to the efficiency and sophistication of the code, enabling programmers to implement complex logic and functionalities.

Scope Resolution (::)

The scope resolution operator, denoted by :: , is used in languages like C++ to access static, constant, and overridden members of a class. For example, ClassName::staticMethod() allows access to a static method of a class without needing to instantiate it. This operator is essential for namespace management and accessing class members in an unambiguous way, especially in large-scale projects where name conflicts might arise.

Arrow (->)

The arrow symbol -> is used in several programming contexts. In C++, it is used to access members of a structure or a class through a pointer. For example, ptr->func() calls the function func() on the object that ptr points to. In languages like PHP, it serves a similar purpose, accessing an object’s properties or methods. The arrow operator provides a concise and clear syntax for pointer and object manipulation.

Programming languages, while sharing some common syntax elements, often utilize symbols differently, offering a rich diversity in coding approaches. This section compares how certain symbols are used across various programming languages, highlighting their unique applications and functionalities.

Symbol Usage in Different Languages

A comparative analysis of symbol usage across languages reveals intriguing differences and similarities. For example, the colon symbol : has varied uses – in Python, it denotes the start of an indented block following structures like loops and conditionals, while in JavaScript, it’s used in object literals to separate keys from values. Similarly, brackets [] are used for array indexing in languages like C and Java, but in Python, they define a list.

Effective symbol usage in programming is not just about understanding their functionality but also about employing them in a way that enhances code clarity, maintainability, and efficiency. Some best practices include:

  • Use clear and consistent naming conventions for variables and functions.
  • Avoid overusing symbols in a way that makes the code cryptic or unreadable.
  • Understand the nuances of symbol usage in the specific language you’re working with.
  • Regularly refactor code to improve its structure and readability.

Symbols in programming languages are like the nuts and bolts in machinery – small but essential. Their proper usage is key to writing efficient, readable, and maintainable code. This exploration of various symbols across different languages underscores the importance of understanding their context-specific applications and nuances.

Sharing is caring

Did you like what Vishnupriya wrote? Thank them for their work by sharing it on social media.

No comment s so far

GCFGlobal Logo

  • Get started with computers
  • Learn Microsoft Office
  • Apply for a job
  • Improve my work skills
  • Design nice-looking docs
  • Getting Started
  • Smartphones & Tablets
  • Typing Tutorial
  • Online Learning
  • Basic Internet Skills
  • Online Safety
  • Social Media
  • Zoom Basics
  • Google Docs
  • Google Sheets
  • Career Planning
  • Resume Writing
  • Cover Letters
  • Job Search and Networking
  • Business Communication
  • Entrepreneurship 101
  • Careers without College
  • Job Hunt for Today
  • 3D Printing
  • Freelancing 101
  • Personal Finance
  • Sharing Economy
  • Decision-Making
  • Graphic Design
  • Photography
  • Image Editing
  • Learning WordPress
  • Language Learning
  • Critical Thinking
  • For Educators
  • Translations
  • Staff Picks
  • English expand_more expand_less

Computer Basics

If you're new to computers or just want to update your skills, you've come to the right place. New videos coming soon!

GCFLearnFree Logo

Introduction

  • 1 About This Tutorial arrow_forward_ios ✓ Learn what's covered in this free course.
  • 2 What is a Computer? arrow_forward_ios ✓ Learn what a computer is and how it functions.

Hardware Basics

  • 3 Basic Parts of a Computer arrow_forward_ios ✓ Learn the basic parts of a computer, including the monitor, computer case, and keyboard.
  • 4 Buttons and Ports on a Computer arrow_forward_ios ✓ Learn the various ports and buttons on a computer.
  • 5 Inside a Computer arrow_forward_ios ✓ Learn what's inside a computer.
  • 6 Laptop Computers arrow_forward_ios ✓ Learn more about laptop computers and how they differ from traditional desktop computers.
  • 7 Mobile Devices arrow_forward_ios ✓ Learn how mobile devices work.

Software Basics

  • 8 Understanding Operating Systems arrow_forward_ios ✓ Get a better understanding of operating systems and how they function.
  • 9 Understanding Applications arrow_forward_ios ✓ Better understand applications and how they work.

Using a Computer

  • 10 Setting Up a Computer arrow_forward_ios ✓ Learn know how to set up a computer.
  • 11 Getting Started with Your First Computer arrow_forward_ios ✓ Get started with your first computer.
  • 12 Getting to Know the OS arrow_forward_ios ✓ Get to know your computer's operating system.

Using the Internet

  • 13 Connecting to the Internet arrow_forward_ios ✓ Learn how to get online and start using the Internet.
  • 14 Getting Started with the Internet arrow_forward_ios ✓ Learn how to get started with and navigate the Internet.
  • 15 Understanding the Cloud arrow_forward_ios ✓ Gain a greater understanding of the cloud and how it works.

Safety and Maintenance

  • 16 Keeping Your Computer Clean arrow_forward_ios ✓ Use these tips to keep your computer clean.
  • 17 Protecting Your Computer arrow_forward_ios ✓ Employ these strategies to keep your computer well protected from threats.
  • 18 Creating a Safe Workspace arrow_forward_ios ✓ Learn tips for creating a safe space at work.
  • 19 Basic Troubleshooting Techniques arrow_forward_ios ✓ Learn these basic troubleshooting techniques.
  • 20 How to Use Your Computer's Built-in Help arrow_forward_ios ✓ Learn how to use your computer's built-in help function.
  • 21 Learning a New Program arrow_forward_ios ✓ Use these tips for learning a new program, whatever it may be.
  • 22 Bringing Your Files with You arrow_forward_ios ✓ Learn how you can bring your computer files and folders with you wherever you go.
  • 23 Using Accessibility Features arrow_forward_ios ✓ Here's how to use your computer's various accessibility functions.
  • 24 Computer Basics Quiz arrow_forward_ios ✓ Test your knowledge of computer basics by taking our quiz.

for Education

  • Google Classroom
  • Google Workspace Admin
  • Google Cloud

Where teaching and learning come together

Google Classroom helps educators create engaging learning experiences they can personalize, manage, and measure. Part of Google Workspace for Education, it empowers educators to enhance their impact and prepare students for the future.

  • Contact sales
  • Sign in to Classroom

150M people worldwide use Google Classroom

Google Classroom is designed with feedback from the educational community, influencing the development of new features that let educators focus on teaching and students focus on learning.

Enrich and personalize learning

Drive student agency with tools that meet students where they are – and build skills for their future.

Premium features that inspire new ways of teaching and learning

Power student potential.

Create interactive assignments, even from existing PDFs, that provide real-time feedback and individual guidance with prompts and hints with the help of AI.

Help students develop literacy skills

Assign differentiated reading activities using the Classroom integration with Read Along, a fun, speech-based tool from Google that helps students independently build their reading skills, while giving educators insight into their progress.

Reinforce concepts with self-paced learning

Assign interactive questions for YouTube videos, giving students real-time feedback as they move through a lesson, while viewing insights into their performance.

Enhance lessons with popular integrations

Easily find, add, use and grade content with add-ons from popular EdTech tools, right within Classroom.

assignment of computer language

Make learning more personal and foster student agency

Support differentiated instruction.

Customize classwork for every student and support them with real-time feedback and easy communication tools.

Foster academic integrity

Encourage original thinking and identify potential plagiarism with originality reports that compare student work against billions of web pages and over 40 million books.

Make learning accessible and inclusive

Help students customize their learning environment to reduce barriers to learning.

Prepare students for the future

Encourage organization and time management skills with interactive to-do lists, automatic due dates, and industry-leading productivity tools.

  • Explore all features

Amplify instruction with tools that simplify everyday tasks

Boost instructional time with tools purpose-built for teaching, productivity, and collaboration.

Premium features that elevate teaching

Support originality with plagiarism detection.

Help students integrate citations and avoid unintentional plagiarism with unlimited originality reports and a school-owned repository of past work.

Streamline lesson planning

Create a link to your class, then share it with peers in your organization, so they can easily preview, select, and import high-quality classwork into their classes.

Inform instruction with data-driven insights

Classroom analytics provide educators with insights and visibility into how students turn in, perform on, and engage with assignments, so educators can make informed decisions about the best way to provide support.

Simplify and connect grading workflows

Sync gradebooks to seamlessly manage and export grades from Classroom to your school’s SIS – available for PowerSchool (coming soon), Infinite Campus, Skyward SMS, Skyward Qmlativ, and Follett Aspen. Educators can customize grading periods (e.g., quarters, semesters, terms) and grading scales (e.g., letter, numeric) in their class settings to align to their school’s grading structure or system, reduce errors for SIS grade export and allow educators to more easily filter and analyze assignments.

assignment of computer language

Tools designed for seamless teaching

Save time on everyday tasks.

Assign, grade, and provide feedback across multiple classes, and even on the go with iOS and Android versions of the Classroom app.

Elevate communication, collaboration, and connection

Connect with students and parents instantly with embedded chat and meeting tools while leveraging built-in chat and comment features to leave students feedback as they’re working.

Grade more efficiently

Assess student progress with customizable rubrics that students can see, and save time with efficient feedback and grade export tools.

Get creative with hundreds of apps

Hundreds of EdTech apps integrate with Classroom to spark creativity and enable more opportunities for learning.

Operate with solutions designed to gain visibility, insights, and control

Create learning environments that are easier to manage and support educators and students with connected, safer tools.

Premium features to support your organization and foster stronger learning outcomes

Make data-driven decisions.

Gain visibility into everything from class performance to individual student assignment completion with Classroom analytics (coming soon), or export Classroom logs to BigQuery to analyze adoption, engagement, and more.

Distribute high-quality class templates to educators

Easily share high-quality class templates so educators in your organization can preview and import classwork into their own classes.

Virtually visit classes to support teachers and students

Designated education leaders and staff can temporarily access classes to support educators, manage substitute teachers, see information for guardian conversations, and more.

Manage classes at scale

Create classes automatically and sync class lists from your student information system (SIS) with Clever .

assignment of computer language

A secure, reliable, and extensible platform for school communities of all sizes

Benefit from industry-leading privacy and security.

Classroom uses the same infrastructure as other Google Workspace products, meeting rigorous privacy standards with regular third-party audits. Access a centralized Admin console with controlled entry and insights into performance and security.

Stay flexible and reliable

Scale your school community with a global network with full-stack security and 99% uptime.

Extend and scale Classroom

Integrate with your student information system (SIS) and customize Classroom to work for your unique needs with APIs.

Support staff and enhance collaboration

Empower educators with instructional resources , professional development programs , and online training courses , available at no cost.

UI

Level up your Classroom with apps

Discover a world of apps that seamlessly integrate with Chromebooks and Google Workspace for Education.

  • Explore App Hub

How Classroom can make a difference for you

Education leaders, it administrators.

An education leader smiles in front of a plain green background.

Classroom can be learned in minutes and serves all types of learners and educators, regardless of their tech savviness. Empower educators, and encourage adoption and proficiency with new tools and techniques, with a broad range of resources.

  • Get a quick overview of the benefits of Classroom
  • Read customer stories
  • Explore trainings and resources for educators
  • 40+ ways to use Google Workspace for Education paid editions
  • Learn about sustainability in Google for Education products

An educator smiles in front of a plain yellow background.

Teachers can immediately set up classes, easily create coursework, distribute it to the whole class, and grade it efficiently and transparently.

  • Find an educator community
  • Download the Classroom user guide
  • View product guides

An IT administrator smiles in front of a plain blue background.

Admins have as much control as they need while they access and analyze their data for insights and choose from a range of upgrade options for additional capabilities to fit their specific needs.

  • Get started with the paid editions of Workspace for Education
  • View product demos
  • Explore 40+ ways to use Google Workspace for Education paid editions
  • Learn more about Google for Education security and privacy
  • Guardian's Guide to Google Classroom

Need more information about Classroom?

  • Visit the Help Center

Bring all of your tools together with Google Workspace for Education

Google Workspace for Education empowers your school community with easy-to-use tools that elevate teaching, learning, collaboration, and productivity – all on one secure platform.

  • Explore Google Workspace for Education

UI

150 million users

Active around the world, ready to transform your school, you're now viewing content for a different region..

For content more relevant to your region, we suggest:

Sign up here for updates, insights, resources, and more.

  • Trending Now
  • Foundational Courses
  • Data Science
  • Practice Problem
  • Machine Learning
  • System Design
  • DevOps Tutorial

What are Operators in Programming?

  • Binary Operators in Programming
  • Unary Operators in Programming
  • Types of Operators in Programming
  • Assignment Operators in Programming
  • Comparison Operators in Programming
  • Ternary Operator in Programming
  • Bitwise AND operator in Programming
  • Bitwise OR Operator (|) in Programming
  • Logical AND operator in Programming
  • Conditional Operator in Programming
  • Right Shift Operator (>>) in Programming
  • Modulus Operator in Programming
  • Operator Associativity in Programming
  • Logical NOT Operator in Programming
  • Pre and Post Decrement Operator in Programming
  • Increment and Decrement Operators in Programming
  • Logical OR operator in Programming
  • Operator Overloading in Dart
  • Relational Operators in C

Operators in programming are essential symbols that perform operations on variables and values , enabling tasks like arithmetic calculations, logical comparisons, and bitwise manipulations. In this article, we will learn about the basics of operators and their types.

Operators-in-Programming

Operators in Programming

Table of Content

  • Operator Precedence and Associativity in Programming
  • Frequently Asked Questions (FAQs) related to Programming Operators

Operators in programming are symbols or keywords that represent computations or actions performed on operands. Operands can be variables , constants , or values , and the combination of operators and operands form expressions. Operators play a crucial role in performing various tasks, such as arithmetic calculations, logical comparisons, bitwise operations, etc.

Operator Symbol Name Type Description Use
+ Addition Arithmetic Operators Adds two values result = num1 + num2;
Subtraction Subtracts the right operand from the left result = num1 – num2;
* Multiplication Multiplies two values result = num1 * num2;
/ Division Divides the left operand by the right result = num1 / num2;
% Modulus Returns the remainder of division result = num1 % num2;
++ Increment Unary Operators Increases the value of a variable by 1 num++; or ++num;
Decrement Decreases the value of a variable by 1 num–; or –num;
= Assignment Assignment Operators Assigns a value to a variable x = 10;
+= Add and Assign Adds the right operand to the left and assigns x += 5; (equivalent to x = x + 5;)
-= Subtract and Assign Subtracts the right operand and assigns x -= 3; (equivalent to x = x – 3;)
*= Multiply and Assign Multiplies the right operand and assigns x *= 2; (equivalent to x = x * 2;)
/= Divide and Assign Divides the left operand and assigns x /= 4; (equivalent to x = x / 4;)
%= Modulus and Assign Computes modulus and assigns x %= 3; (equivalent to x = x % 3;)
== Equal to Relational or Comparison Operators Tests if two values are equal if (a == b)
!= Not Equal to Tests if two values are not equal if (a != b)
< Less Than Tests if the left value is less than the right if (a < b)
> Greater Than Tests if the left value is greater than right if (a > b)
<= Less Than or Equal To Tests if the left value is less than or equal if (a <= b)
>= Greater Than or Equal To Tests if the left value is greater than or equal if (a >= b)
&& Logical AND Logical Operators Returns true if both operands are true if (a && b)
|| Logical OR
! Logical NOT Reverses the logical state of its operand if (!condition)
& Bitwise AND Bitwise Operators Performs bitwise AND on individual bits result = a & b;
` Bitwise OR Performs bitwise OR on individual bits
^ Bitwise XOR Performs bitwise XOR on individual bits result = a ^ b;
~ Bitwise NOT Inverts the bits of its operand result = ~a;
<< Left Shift Shifts bits to the left result = a << 2;
>> Right Shift Shifts bits to the right result = a >> 1;
?: Conditional (Ternary) Conditional Operator Evaluates a condition and returns one of two values result = (condition) ? value1 : value2;

Types of Operators in Programming:

Here are some common types of operators:

  • Arithmetic Operators: Perform basic arithmetic operations on numeric values. Examples: + (addition), – (subtraction), * (multiplication), / (division), % (modulo).
  • Comparison Operators: Compare two values and return a Boolean result (true or false). Examples: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to).
  • Logical Operators: Perform logical operations on Boolean values. Examples: && (logical AND), || (logical OR), ! (logical NOT).
  • Assignment Operators: Assign values to variables. Examples: = (assign), += (add and assign), -=, *= (multiply and assign), /=, %=.
  • Increment and Decrement Operators: Increase or decrease the value of a variable by 1. Examples: ++ (increment), — (decrement).
  • Bitwise Operators: Perform operations on individual bits of binary representations of numbers. Examples: & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), >> (right shift).

These operators provide the building blocks for creating complex expressions and performing diverse operations in programming languages. Understanding their usage is crucial for writing efficient and expressive code.

Arithmetic Operators in Programming:

Arithmetic operators in programming are fundamental components of programming languages, enabling the manipulation of numeric values for various computational tasks. Here’s an elaboration on the key arithmetic operators:

Operator Description Examples
+ (Addition) Combines two numeric values, yielding their sum. (result will be 8)
– (Subtraction) Subtracts the right operand from the left operand. (difference will be 6)
* (Multiplication) Multiplies two numeric values, producing their product. (product will be 21)
/ (Division) Divides the left operand by the right operand, producing a quotient. (quotient will be 5)
% (Modulo) Returns the remainder after the division of the left operand by the right operand. (remainder will be 1)

Comparison Operators in Programming:

Comparison operators in programming are used to compare two values or expressions and return a Boolean result indicating the relationship between them. These operators play a crucial role in decision-making and conditional statements. Here are the common comparison operators:

Operator Description Examples
== (Equal to) Checks if the values on both sides are equal. (evaluates to true)
!= (Not equal to) Checks if the values on both sides are not equal. (evaluates to true)
< (Less than) Tests if the value on the left is less than the value on the right. (evaluates to true)
> (Greater than) Tests if the value on the left is greater than the value on the right. (evaluates to true)
<= (Less than or equal to) Checks if the value on the left is less than or equal to the value on the right. (evaluates to true)
>= (Greater than or equal to) Checks if the value on the left is greater than or equal to the value on the right. (evaluates to true)

These operators are extensively used in conditional statements, loops, and decision-making constructs to control the flow of a program based on the relationship between variables or values. Understanding comparison operators is crucial for creating logical and effective algorithms in programming.

Logical Operators in Programming:

Logical operators in programming are used to perform logical operations on Boolean values . These operators are crucial for combining or manipulating conditions and controlling the flow of a program based on logical expressions. Here are the common logical operators:

Operator Description Examples
&& (Logical AND) Returns true if both operands are true; otherwise, it returns false. (evaluates to false)
(||) Logical OR Returns true if at least one of the operands is true; otherwise, it returns false

true || false; (evaluates to true)

! (Logical NOT) Returns true if the operand is false and vice versa; it negates the Boolean value. (evaluates to false)

These logical operators are frequently used in conditional statements (if, else if, else), loops, and decision-making constructs to create complex conditions based on multiple Boolean expressions. Understanding how to use logical operators is essential for designing effective and readable control flow in programming.

Assignment Operators in Programming:

Assignment operators in programming are used to assign values to variables. They are essential for storing and updating data within a program. Here are common assignment operators:

Operator Description Examples
= (Assignment) Assigns the value on the right to the variable on the left. assigns the value 10 to the variable x.
+= (Addition Assignment) Adds the value on the right to the current value of the variable on the left and assigns the result to the variable. is equivalent to
-= (Subtraction Assignment) Subtracts the value on the right from the current value of the variable on the left and assigns the result to the variable. is equivalent to
*= (Multiplication Assignment) Multiplies the current value of the variable on the left by the value on the right and assigns the result to the variable. is equivalent to
/= (Division Assignment) Divides the current value of the variable on the left by the value on the right and assigns the result to the variable. is equivalent to
%= (Modulo Assignment) Calculates the modulo of the current value of the variable on the left and the value on the right, then assigns the result to the variable. is equivalent to

Assignment operators are fundamental for updating variable values, especially in loops and mathematical computations, contributing to the dynamic nature of programming. Understanding how to use assignment operators is essential for effective variable manipulation in a program.

Increment and Decrement Operators in Programming:

Increment and decrement operators in programming are used to increase or decrease the value of a variable by 1, respectively. They are shorthand notations for common operations and are particularly useful in loops. Here are the two types:

Operator Description Examples
++ (Increment) Increases the value of a variable by 1. is equivalent to or
— (Decrement) Decreases the value of a variable by 1. is equivalent to or

These operators are frequently employed in loops, especially for iterating through arrays or performing repetitive tasks. Their concise syntax enhances code readability and expressiveness.

Bitwise Operators in Programming:

Bitwise operators in programming perform operations at the bit level , manipulating individual bits of binary representations of numbers. These operators are often used in low-level programming, such as embedded systems and device drivers. Here are the common bitwise operators:

Operator Description Examples
& (Bitwise AND) Performs a bitwise AND operation between corresponding bits of two operands. sets each bit to 1 if both corresponding bits in A and B are 1.
| (Bitwise OR) Performs a bitwise OR operation between corresponding bits of two operands. A | B sets each bit to 1 if at least one corresponding bit in A or B is 1.
^ (Bitwise XOR) Performs a bitwise XOR (exclusive OR) operation between corresponding bits of two operands. sets each bit to 1 if the corresponding bits in A and B are different.
~ (Bitwise NOT) Inverts the bits of a single operand, turning 0s to 1s and vice versa. inverts all bits of A.
<< (Left Shift) Shifts the bits of the left operand to the left by a specified number of positions. shifts the bits of A two positions to the left.
>> (Right Shift) Shifts the bits of the left operand to the right by a specified number of positions. shifts the bits of A three positions to the right.

Bitwise operators are useful in scenarios where direct manipulation of binary representations or specific bit patterns is required, such as optimizing certain algorithms or working with hardware interfaces. Understanding bitwise operations is essential for low-level programming tasks.

Operator Precedence and Associativity in Programming :

Operator Precedence is a rule that determines the order in which operators are evaluated in an expression. It defines which operators take precedence over others when they are combined in the same expression. Operators with higher precedence are evaluated before operators with lower precedence. Parentheses can be used to override the default precedence and explicitly specify the order of evaluation.

Operator Associativity is a rule that determines the grouping of operators with the same precedence in an expression when they appear consecutively. It specifies the direction in which operators of equal precedence are evaluated. The two common associativities are:

  • Left to Right (Left-Associative): Operators with left associativity are evaluated from left to right. For example, in the expression a + b + c , the addition operators have left associativity, so the expression is equivalent to (a + b) + c .
  • Right to Left (Right-Associative): Operators with right associativity are evaluated from right to left. For example, in the expression a = b = c , the assignment operator = has right associativity, so the expression is equivalent to a = (b = c) .
Precedence Operator Description Associativity
1 () Parentheses Left-to-Right
x++, x– Postfix increment, decrement
2 ++x, –x Prefix increment, decrement Right-to-Left
‘+’ , ‘-‘ Unary plus, minus
! , ~ Logical NOT, Bitwise complement
* Dereference Operator
& Addressof Operator
3 *, /, % Multiplication, division, modulus Left-to-Right
4 +, – Addition, subtraction Left-to-Right
5 << , >> Bitwise shift left, Bitwise shift right Left-to-Right
6 < , <= Relational less than, less than or equal to Left-to-Right
> , >= Relational greater than, greater than or equal to
7 == , != Relational is equal to, is not equal to Left-to-Right
8 & Bitwise AND Left-to-Right
9 ^ Bitwise XOR Left-to-Right
10 | Bitwise OR Left-to-Right
11 && Logical AND Left-to-Right
12 || Logical OR Left-to-Right
13 ?: Ternary conditional Right-to-Left
14 = Assignment Right-to-Left
+= , -= Addition, subtraction assignment
*= , /= Multiplication, division assignment
%= , &= Modulus, bitwise AND assignment
^= , |= Bitwise exclusive, inclusive OR assignment
<<=, >>= Bitwise shift left, right assignment
15 , comma (expression separator) Left-to-Right

Frequently Asked Questions (FAQs) related to Programming Operators :

Here are some frequently asked questions (FAQs) related to programming operators:

Q1: What are operators in programming?

A: Operators in programming are symbols that represent computations or actions to be performed on operands. They can manipulate data, perform calculations, and facilitate various operations in a program.

Q2: How are operators categorized?

A: Operators are categorized based on their functionality. Common categories include arithmetic operators (for mathematical operations), assignment operators (for assigning values), comparison operators (for comparing values), logical operators (for logical operations), and bitwise operators (for manipulating individual bits).

Q3: What is the difference between unary and binary operators?

A: Unary operators operate on a single operand, while binary operators operate on two operands. For example, the unary minus -x negates the value of x , while the binary plus a + b adds the values of a and b .

Q4: Can operators be overloaded in programming languages?

A: Yes, some programming languages support operator overloading, allowing developers to define custom behaviors for operators when applied to user-defined types. This is commonly seen in languages like C++.

Q5: How do logical AND ( && ) and logical OR ( || ) operators work?

A: The logical AND ( && ) operator returns true if both of its operands are true. The logical OR ( || ) operator returns true if at least one of its operands is true. These operators are often used in conditional statements and expressions.

Q6: What is the purpose of the ternary operator ( ?: )?

A: The ternary operator is a shorthand for an if-else statement. It evaluates a condition and returns one of two values based on whether the condition is true or false. It is often used for concise conditional assignments.

Q7: How does the bitwise XOR operator ( ^ ) work?

A: The bitwise XOR ( ^ ) operator performs an exclusive OR operation on individual bits. It returns 1 for bits that are different and 0 for bits that are the same. This operator is commonly used in bit manipulation tasks.

Q8: What is the difference between = and == ?

A: The = operator is an assignment operator used to assign a value to a variable. The == operator is a comparison operator used to check if two values are equal. It is important not to confuse the two, as = is used for assignment, and == is used for comparison.

Q9: How do increment ( ++ ) and decrement ( -- ) operators work?

A: The increment ( ++ ) operator adds 1 to the value of a variable, while the decrement ( -- ) operator subtracts 1. These operators can be used as prefix ( ++x ) or postfix ( x++ ), affecting the order of the increment or decrement operation.

Q10: Are operators language-specific?

A: While many operators are common across programming languages, some languages may introduce unique operators or have variations in their behavior. However, the fundamental concepts of arithmetic, logical, and bitwise operations are prevalent across various languages.

Q11: What is the modulus operator ( % ) used for?

A: The modulus operator ( % ) returns the remainder when one number is divided by another. It is often used to check divisibility or to cycle through a sequence of values. For example, a % 2 can be used to determine if a is an even or odd number.

Q12: Can the same operator have different meanings in different programming languages?

A: Yes, the same symbol may represent different operators or operations in different programming languages. For example, the + operator is used for addition in most languages, but in some languages (like JavaScript), it is also used for string concatenation.

Q13: What is short-circuit evaluation in the context of logical operators?

A: Short-circuit evaluation is a behavior where the second operand of a logical AND ( && ) or logical OR ( || ) operator is not evaluated if the outcome can be determined by the value of the first operand alone. This can lead to more efficient code execution.

Q14: How are bitwise left shift ( << ) and right shift ( >> ) operators used?

A: The bitwise left shift ( << ) operator shifts the bits of a binary number to the left, effectively multiplying the number by 2. The bitwise right shift ( >> ) operator shifts the bits to the right, effectively dividing the number by 2.

Q15: Can you provide an example of operator precedence in programming?

A: Operator precedence determines the order in which operators are evaluated. For example, in the expression a + b * c , the multiplication ( * ) has higher precedence than addition ( + ), so b * c is evaluated first.

Q16: How does the ternary operator differ from an if-else statement?

A: The ternary operator ( ?: ) is a concise way to express a conditional statement with a single line of code. It returns one of two values based on a condition. An if-else statement provides a more extensive code block for handling multiple statements based on a condition.

Q17: Are there any operators specifically designed for working with arrays or collections?

A: Some programming languages provide specific operators or methods for working with arrays or collections. For example, in Python, the in operator is used to check if an element is present in a list.

Q18: How can bitwise operators be used for efficient memory management?

A: Bitwise operators are often used for efficient memory management by manipulating individual bits. For example, bitwise AND can be used to mask specific bits, and bitwise OR can be used to set particular bits.

Q19: Can operators be overloaded in all programming languages?

A: No, not all programming languages support operator overloading. While some languages like C++ allow developers to redefine the behavior of operators for user-defined types, others, like Java, do not permit operator overloading.

Q20: How do you handle operator precedence in complex expressions?

A: Parentheses are used to explicitly specify the order of operations in complex expressions, ensuring that certain operations are performed before others. For example, (a + b) * c ensures that addition is performed before multiplication.

In conclusion, operators in programming are essential tools that enable the manipulation, comparison, and logical operations on variables and values. They form the building blocks of expressions and play a fundamental role in controlling program flow, making decisions, and performing calculations. From arithmetic and comparison operators for numerical tasks to logical operators for decision-making, and bitwise operators for low-level bit manipulation, each type serves specific purposes in diverse programming scenarios.

Please Login to comment...

Similar reads.

  • Programming

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

COMMENTS

  1. What is a Programming Language? Definition and Types

    A computer "speaks" in a "language" using strings of the numerals "1" and "0"—known as binary code. A programming language allows us to translate the computer's binary code into something humans can understand and write. These languages enable us to communicate with computers, build and organize code, specify functionality and behavior ...

  2. Assignment (computer science)

    Assignment (computer science) In computer programming, an assignment statement sets and/or re-sets the value stored in the storage location (s) denoted by a variable name; in other words, it copies a value into the variable. In most imperative programming languages, the assignment statement (or expression) is a fundamental construct.

  3. How to Learn Programming

    A higher-level programming language provides a set of human-readable keywords, statements, and syntax rules that are much simpler for people to learn, debug, and work with. Programming languages provide a means of bridging the gap between the way our human brains understand the world and the way computer brains (CPUs) understand the world.

  4. Assignments

    Assignments. pdf. 98 kB Getting Started: Python and IDLE. file. 193 B shapes. file. 3 kB ... Electrical Engineering and Computer Science; As Taught In ... Topics Engineering. Computer Science. Programming Languages; Over 2,500 courses & materials Freely sharing knowledge with learners and educators around the world. Learn more

  5. Computer programming

    Community. In this course, you'll explore the wonders of what you can create with programming. Learn how to program drawings, animations, and games using JavaScript and the Processing library, and explore the technologies behind the web as you design webpages with HTML and CSS.

  6. 5 Types of Programming Languages

    Some popular functional programming languages include: Scala. Erlang. Haskell. Elixir. F#. 3. Object-oriented programming languages (OOP) This type of language treats a program as a group of objects composed of data and program elements, known as attributes and methods.

  7. Quick Guide to Top Coding Languages

    Ruby is a general-purpose, high-level, and open-source programming language that is easy to learn. Why Ruby Is Important: Ruby is popular for web development, 3D modeling, and data processing. Developers value its security, free cost, and fast processing speed. Where Ruby Is Used: Grubhub, Policygenius, MassMutual.

  8. The C Programming Handbook for Beginners

    This is because C is considered the "mother of programming languages" and is one of the most foundational languages of computer science. Most modern and popular languages used today either use C under the hood or are inspired by it. ... The assignment operator works by evaluating the expression on the right-hand side and then storing its result ...

  9. Programming language

    Programming language. The source code for a computer program in C. The gray lines are comments that explain the program to humans. When compiled and run, it will give the output "Hello, world!". A programming language is a system of notation for writing computer programs. [1]

  10. PDF Principles of Programming Languages

    ming languages, including Python, Java, and C, are fundamentally imperative in nature: inspired by the Turing machine model of computation, programs in these languages are organized around statements corresponding to instructions that the computer should execute.6 In this model, we think of "running" a pro-6 "Statement" here includes larger

  11. What Is Programming? And How To Get Started

    At its most basic, programming tells a computer what to do. First, a programmer writes code—a set of letters, numbers, and other characters. Next, a compiler converts each line of code into a language a computer can understand. Then, the computer scans the code and executes it, thereby performing a task or series of tasks.

  12. Generation of Programming Languages

    It's also called High-Level Programming Language. For execution, a program in this language needs to be translated into machine language using a Compiler/ Interpreter. Examples of this type of language are C, PASCAL, FORTRAN, COBOL, etc. Advantages : 1. Use of English-like words makes it a human-understandable language. 2.

  13. Assignment

    The assignment operator allows us to change the value of a modifiable data object (for beginning programmers this typically means a variable). It is associated with the concept of moving a value into the storage location (again usually a variable). Within most programming languages the symbol used for assignment is the equal symbol.

  14. PDF Programming Languages Overview & Syntax

    » Low-level languages give the programmer more control (at the cost of requiring more effort) over how the program is translated into machine code. • C, FORTRAN » High-level languages hide many implementation details, often with some performance cost • BASIC, LISP, SCHEME, ML, PROLOG, » Wide-spectrum languages try to do both:

  15. Computer programming language

    computer programming language, any of various languages for expressing a set of detailed instructions for a digital computer.Such instructions can be executed directly when they are in the computer manufacturer-specific numerical form known as machine language, after a simple substitution process when expressed in a corresponding assembly language, or after translation from some "higher ...

  16. Assignment Operators in C

    1. "=": This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left. Example: a = 10; b = 20; ch = 'y'; 2. "+=": This operator is combination of '+' and '=' operators. This operator first adds the current value of the variable on left to the value on the right and ...

  17. Computer Fundamentals Tutorial

    Functionalities of Computer. Any digital computer performs the following five operations: Step 1 − Accepts data as input. Step 2 − Saves the data/instructions in its memory and utilizes them as and when required. Step 3 − Execute the data and convert it into useful information. Step 4 − Provides the output.

  18. Popular Coding Symbols in Programming Languages

    It is used to assign values to variables. In most languages, the operator takes the value on its right and stores it in the variable on its left. For instance, x = 5 assigns the value 5 to the variable x. It's essential to differentiate between the assignment operator and the equality operator (== in many languages), which is used for comparison.

  19. Types of Computer Languages With Their Advantages and ...

    Two Basic Types of Computer Language. Low-Level Languages: A language that corresponds directly to a specific machine. High-Level Languages: Any language that is independent of the machine. There are also other types of languages, which include. System languages: These are designed for low-level tasks, like memory and process management.

  20. PDF CS/COE0447: Computer Organization and Assembly Language

    Late Assignments & Regrading. Late assignments. Project can be submitted late up to 5 days, 20% penalty each day. Assignments without penalty will be accepted only with approved excuse by your instructor, with written documentation. Events (sports, clubs, etc.) need prior approval for late submission. Completed within one week of original date.

  21. Assignment Operators in Programming

    Assignment operators are used in programming to assign values to variables. We use an assignment operator to store and update data within a program. They enable programmers to store data in variables and manipulate that data. The most common assignment operator is the equals sign (=), which assigns the value on the right side of the operator to ...

  22. Free Computer Basics Tutorial at GCFGlobal

    Basic Parts of a Computer Learn the basic parts of a computer, including the monitor, computer case, and keyboard. 4. Buttons and Ports on a Computer Learn the various ports and buttons on a computer. 5. Inside a Computer Learn what's inside a computer. 6.

  23. Classroom Management Tools & Resources

    Help students develop literacy skills. Assign differentiated reading activities using the Classroom integration with Read Along, a fun, speech-based tool from Google that helps students independently build their reading skills, while giving educators insight into their progress. Express interest in the early access program.

  24. What are Operators in Programming?

    Operators in programming are symbols or keywords that represent computations or actions performed on operands. Operands can be variables, constants, or values, and the combination of operators and operands form expressions. Operators play a crucial role in performing various tasks, such as arithmetic calculations, logical comparisons, bitwise ...

  25. What Is Effective Communication? Skills for Work, School, and Life

    Say it with your body. In face-to-face conversation, body language plays an important role. Communication is 55 percent non-verbal, 38 percent vocal (tone and inflection), and 7 percent words, according to Albert Mehrabian, a researcher who pioneered studies on body language [].Up to 93 percent of communication, then, does not involve what you are actually saying.