Course contentsShow
← C
Lesson 107 of 1,2192. Variables and TypesFree lesson

Single quotes vs. double quotes

Single quotes vs. double quotes

What you'll learn: How to distinguish between a single character and a sequence of text by choosing the correct punctuation.

In C, punctuation isn't just for decoration; it tells the compiler exactly how much memory to set aside for your data. When dealing with text, the most common mistake beginners make is swapping single quotes (' ') for double quotes (" "). While they look similar, C treats them as completely different animals.

The single character ('A')

Single quotes are used exclusively for a single char. Think of single quotes like a small, individual coin slot. You can fit exactly one letter, one number, or one symbol inside.

When you write 'A', the compiler looks at the ASCII table and sees the number 65. In C, a char is actually just a small integer under the hood. Because it is just one single value, it fits into a tiny cubby hole in your computer's memory.

The string ("A")

Double quotes are used for strings (sequences of characters). Think of double quotes like a train. Even if the train only has one passenger, it still needs tracks, a locomotive, and—most importantly—a "caboose" at the end to signal that the train is finished.

In C, every string automatically adds a hidden character at the end called a "null terminator" (\0). So, while 'A' is just one piece of data, "A" is actually two: the letter 'A' and the hidden "stop" sign.

Spotting the difference in code

If you try to put multiple letters in single quotes, or if you try to treat a double-quoted string like a simple number, the compiler will get confused and throw an error.

#include <stdio.h>

int main() {
    // A single character: uses 1 byte of memory
    char grade = 'A'; 

    // A string: uses 2 bytes (one for 'A', one for the hidden \0)
    char name[] = "A"; 

    printf("Single quotes are for characters: %c\n", grade);
    printf("Double quotes are for strings: %s\n", name);

    return 0;
}

Why it matters

Imagine you are filling out a form that asks for your "Middle Initial." You would use single quotes because only one letter fits. If the form asks for your "Full Name," you would use double quotes. Using the wrong one in C is like trying to park a full-sized bus in a bicycle rack—it simply won't fit the way the language expects.

Key takeaway

Use single quotes for a single character ('a') and double quotes for any amount of text ("abc"), even if it's only one letter long.