×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

Format specifier for unsigned short int

Learn about the format specifier for unsigned short int, i.e., which format specifier is used with the unsigned short int variables in C language?
Submitted by Shubh Pachori, on July 07, 2022

In C language the format specifier we use for the unsigned short int is %hu. %hu is used to read and display results that are to be stored or already stored in the unsigned short int variable.

Format specifier for unsigned short int in C

In C language there are many data types like, unsigned char, signed char or char, unsigned int, signed int or int, unsigned short int, signed short int or short int, unsigned long int, signed long int or long int, long double, double, float, etc. The size and range of data types depend a lot on the compiler. However, the code that the compiler compiles is targeted for some specific types of microcontrollers or microprocessors. The format specifiers are used in C for input and output purposes. Using this concept the compiler can understand what type of data is in a variable during taking input using the scanf() function and printing using the printf() function.

Here is a table of different data types with their range, size, and format specifiers.

Example - Format specifier for unsigned short int

Consider the below given code for better understanding.

#include <stdio.h>

int main()
{
    //declaring unsigned short int variables
    unsigned short int usi;

    //declaring int, float, double, and char variables
    int i;
    float f;
    double d;
    char c;

    printf("Enter Character: ");
    scanf("%c", &c);

    printf("Enter Unsigned Short Int: ");
    scanf("%hu", &usi);

    printf("Enter Int: ");
    scanf("%d", &i);

    printf("Enter Float: ");
    scanf("%f", &f);

    printf("Enter Double: ");
    scanf("%lf", &d);

    printf("Unsigned Short Int: %hu\nInt: %d\nFloat: %f\nDouble: %lf\nCharacter: %c", usi, i, f, d, c);

    return 0;
}

Output:

Enter Character: R
Enter Unsigned Short Int: 1234
Enter Int: 12
Enter Float: 12.34
Enter Double: 2323.243
Unsigned Short Int: 1234
Int: 12
Float: 12.340000
Double: 2323.243000
Character: R



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.