C Programming Tutorial 40 – How to use the Type Cast Operator

Did you read the last blog? Go read it on Implicit Type Promotion! Are you new here? Start at the beginning, Intro to C!

Now, let’s give an example of explicit conversion:

In this situation, we are splitting the pieces of pizza with our friend.  We are trying to figure out how many pieces each person should get.

Both operands are integers, so the result will be an integer.  There are two ways we can fix this. First, we can add .0 to the 2.  This works, but it will not always work. For example, we could have this:

Continue reading “C Programming Tutorial 40 – How to use the Type Cast Operator”

C Programming Tutorial 39 – Implicit Type Promotion

The previous blog was foundational to this blog, so go read that first! Are you new here? Start at the beginning, Intro to C!

Essentially, casting is when something of a certain data type is converted to a different data type.

This blog is going to be showing examples of both implicit casting and explicit casting. When you study implicit conversion in C, you will likely come across the term promotion.

Continue reading “C Programming Tutorial 39 – Implicit Type Promotion”

C Programming Tutorial 38 – Type Casting

Did you read the last blog on Strongly Typed Vs Loosely Typed Languages? Are you new here? Start at the beginning, Intro to C!

In the previous video we mentioned how C was a strongly typed language. Imagine C as a grumpy old man who you owe a dollar bill to. Well, he wants his money now, but all you have is some change.

You look at your change, grab four quarters, and find out that it adds up to exactly a dollar. But unfortunately, you owe him a dollar bill, not just 100 cents. So yeah, he beats you over the head with his cane.

Continue reading “C Programming Tutorial 38 – Type Casting”

C Programming Tutorial 37 – Strongly Typed Vs Loosely Typed Languages

Did you read the last blog on Operator Precedence? Are you new here? Start at the beginning, Intro to C!

This blog is going to be an introduction to how programming languages consider data types. As we know, there are many data types in C programming. C is an example of a strongly typed programming language. Strongly typed means that every piece of data has a specific type.

Concatenation

Imagine if we stored everything in strings. This would become a problem because the computer would never know how to work with certain data. For example, let’s say we have “5” and “6” and we try to add them. Should the computer add the numbers to be “11”, or should it combine the strings to be “56” (The process of combining two strings like this is known as concatenation).

Continue reading “C Programming Tutorial 37 – Strongly Typed Vs Loosely Typed Languages”

C Programming Tutorial 36 – Operator Precedence

Did you read the last blog on Assignment Operators? Are you new here? Start at the beginning, Intro to C!

You may have heard from math class of this fancy thing called order of operations. We discussed this in a previous video so I’m not going to waste your time by repeating myself, but I am going to look at the same concept from a bigger point of view.

Precedence and Associativity

The point of the order of operations is to say which operators happen first and from which direction. For example, we know for the c operators, the multiplication happens first. This order in which operators happen is known as precedence.

Continue reading “C Programming Tutorial 36 – Operator Precedence”

C Programming Tutorial 35 – Assignment Operators

Did you read the last blog on Increment and Decrement Operators? Are you new here? Start at the beginning, Intro to C!

In the previous blog I showed you how you can add one to a variable.  You can use the ++ operator. I also showed you what to do if you wanted to add more than one to a variable.  For example, we can have something like this:

Continue reading “C Programming Tutorial 35 – Assignment Operators”

C Programming Tutorial 34 – Increment and Decrement Operators

Did you read the last blog on Unary Plus and Minus? Are you new here? Start at the beginning, Intro to C!

Let’s say we have a variable and we want to add one to it.

The hard way to do this is to go like this:

What the assignment operator does here is take the entire expression on the right and evaluate it to a value. So pizzasToEat + 1 = 124. Then, it assigns that value to the variable on the left. So now pizza will equal 124. We can output this data before and after to see this in action.

Continue reading “C Programming Tutorial 34 – Increment and Decrement Operators”

C Programming Tutorial 33 – Unary Plus and Minus

Did you read the last blog on Modulus Operators? Are you new here? Start at the beginning, Intro to C!

This video is going to be talking about the minus and plus operator.  But wait, don’t leave yet. We’re not talking about the binary minus and plus operators, rather the unary ones.  As a reminder, the difference is how many operands they work on. The binary minus operator, for example, will take one operand, subtract the second operand from it, and generate a result from that.  Neither of the operands are modified.

Continue reading “C Programming Tutorial 33 – Unary Plus and Minus”

C Programming Tutorial 32 – Modulus Operator

Did you read the last blog on Arithmetic Operators? Are you new here? Start at the beginning, Intro to C!

This video is going to introduce you to a new operator called the modulus operator (%).

In the last video I gave you this example:

I told you that the value of y is going to be 1.  Did you figure out what this operator does? Well it actually takes the remainder.  I’ve always been pretty bad at visualizing a remainder, so I use imagery. Imagine you have a pizza with 5 slices and you want to share the pizza with your pet rat, Pepper Jack.

Continue reading “C Programming Tutorial 32 – Modulus Operator”

C Programming Tutorial 31 – Arithmetic Operators

Did you read the last blog on Intro to Operators? Are you new here? Start at the beginning, Intro to C!

This blog is going to discuss the arithmetic operators. Now, we’ve discussed these some already and I’m sure you are familiar with them from math classes you’ve taken so this blog is really not going to be that hard or confusing!

The arithmetic operators include the +, -, /, and *. These are all binary operators that need two operands.

The / is called a forward slash. Some people call \ a forward slash and they are wrong! The top of the slash is the reference point, not the bottom. The top is leaning forward, therefore / is called the forward slash.

Continue reading “C Programming Tutorial 31 – Arithmetic Operators”