size of char datatype and char array in C - GeeksforGeeks (2024)

Improve Article

Save Article

  • Difficulty Level :Easy
  • Last Updated :15 Oct, 2019

Improve Article

Save Article

Given a char variable and a char array, the task is to write a program to find the size of this char variable and char array in C.

Examples:

Input: ch = 'G', arr[] = {'G', 'F', 'G'}Output: Size of char datatype is: 1 byteSize of char array is: 3 byteInput: ch = 'G', arr[] = {'G', 'F'}Output: Size of char datatype is: 1 byteSize of char array is: 2 byte

Approach:
In the below program, to find the size of the char variable and char array:

  • first, the char variable is defined in charType and the char array in arr.
  • Then, the size of the char variable is calculated using sizeof() operator.
  • Then the size of the char array is find by dividing the size of the complete array by the size of the first variable.

Below is the C program to find the size of the char variable and char array:

// C program to find the size of

// char data type and char array

#include <stdio.h>

int main()

{

char charType = 'G';

char arr[] = { 'G', 'F', 'G' };

// Calculate and Print

// the size of charType

printf("Size of char datatype is: %ld byte\n",

sizeof(charType));

// Calculate the size of char array

size_t size = sizeof(arr) / sizeof(arr[0]);

// Print the size of char array

printf("Size of char array is: %ld byte",

size);

return 0;

}

Output:

Size of char datatype is: 1 byteSize of char array is: 3 byte

My Personal Notesarrow_drop_up

size of char datatype and char array in C - GeeksforGeeks (2024)
Top Articles
How Much House Can I Afford?
11 Habits of Debt-Free Families
Frederick County Craigslist
Maria Dolores Franziska Kolowrat Krakowská
Ret Paladin Phase 2 Bis Wotlk
Workday Latech Edu
Poplar | Genus, Description, Major Species, & Facts
Select The Best Reagents For The Reaction Below.
Bank Of America Appointments Near Me
Dark Souls 2 Soft Cap
How Quickly Do I Lose My Bike Fitness?
Raid Guides - Hardstuck
Inevitable Claymore Wow
Lenscrafters Huebner Oaks
Gwdonate Org
The Witcher 3 Wild Hunt: Map of important locations M19
Rainfall Map Oklahoma
Patrick Bateman Notebook
2 Corinthians 6 Nlt
Parentvue Clarkston
Scotchlas Funeral Home Obituaries
R. Kelly Net Worth 2024: The King Of R&B's Rise And Fall
Galaxy Fold 4 im Test: Kauftipp trotz Nachfolger?
A Man Called Otto Showtimes Near Cinemark University Mall
Living Shard Calamity
Firefly Festival Logan Iowa
Craigslist Northern Minnesota
30+ useful Dutch apps for new expats in the Netherlands
Wcostream Attack On Titan
Workboy Kennel
Capital Hall 6 Base Layout
Craigslist Summersville West Virginia
Frcp 47
Rochester Ny Missed Connections
The Minneapolis Journal from Minneapolis, Minnesota
Überblick zum Barotrauma - Überblick zum Barotrauma - MSD Manual Profi-Ausgabe
Pokemon Reborn Gyms
Pa Legion Baseball
Doe Infohub
Gregory (Five Nights at Freddy's)
Sechrest Davis Funeral Home High Point Nc
BCLJ July 19 2019 HTML Shawn Day Andrea Day Butler Pa Divorce
Po Box 101584 Nashville Tn
Ts In Baton Rouge
Benjamin Franklin - Printer, Junto, Experiments on Electricity
Sams Gas Price San Angelo
Dineren en overnachten in Boutique Hotel The Church in Arnhem - Priya Loves Food & Travel
Suppress Spell Damage Poe
Minute Clinic Mooresville Nc
Great Clips Virginia Center Commons
Nfsd Web Portal
Latest Posts
Article information

Author: Lilliana Bartoletti

Last Updated:

Views: 5785

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Lilliana Bartoletti

Birthday: 1999-11-18

Address: 58866 Tricia Spurs, North Melvinberg, HI 91346-3774

Phone: +50616620367928

Job: Real-Estate Liaison

Hobby: Graffiti, Astronomy, Handball, Magic, Origami, Fashion, Foreign language learning

Introduction: My name is Lilliana Bartoletti, I am a adventurous, pleasant, shiny, beautiful, handsome, zealous, tasty person who loves writing and wants to share my knowledge and understanding with you.