Size of an Array using sizeof Operator OR strlen() Function in C

Question: Can we Determine Size of an Array using sizeof Operator and strlen() Function in C Language? Answer: Let’s learn this by considering an example, and analysing it’s output when program is run on Linux System. /* * sizeof_vs_strlen.c — program shows difference between using sizeof and * strlen with array and string */ #include … Read more

advertisement

Array of Pointers in C with Examples

This C Tutorial Explains an Array of Pointers in C with Examples. What is an array? Array is a variable that can store multiple values ​​in a single variable rather than having separate variables for each element. What is a Pointer? Pointer is a variable, which stores the address of another variable. It stores the … Read more

advertisement

How to Pass a 2D Array as a Function Arguments in C?

This C Tutorial Explains Multidimensional Arrays Passed as Function Arguments in C with Example(s). Let’s, first, take an example of a 2-dimensional array, int hawks[4][5] = {{1,2,3,4,5}, {6,7,8,9,10}, {11,12,13,14,15}, {16,17,18,19,20}, }; /* hawks’s initialized here */ In order to pass ‘hawks’ as a function argument, we must know type of array ‘hawks’, so that we … Read more

advertisement

Pointer to an Array in C

This C Tutorial Explains Pointer to Array in C with Example(s). A pointer is a variable whose contents is an address of some location in memory. For example: int val = 10, new = 20; int *ptr = &val; /* ‘ptr’ points to ‘val’ */   ptr = &new; /* ‘ptr’ now points to ‘new’ … Read more

advertisement

How does C Allocate Memory of Data Elements in a Multidimensional Array?

This C Tutorial Explains how Elements in a Multidimensional Array in C are Stored in Memory with an Example. A multidimensional array can be thought of as a one-dimensional array with composite elements. For example: int flags[3][2][5][4]= { { {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16},{17,18,19,20}}, {{21,22,23,24},{25,26,27,28},{29,30,31,32},{33,34,35,36},{37,38,39,40}} }, { {{41,42,43,44},{45,46,47,48},{49,50,51,52},{53,54,55,56},{57,58,59,60}}, {{61,62,63,64},{65,66,67,68},{69,70,71,72},{73,74,75,76},{77,78,79,80}} }, { {{81,82,83,84},{85,86,87,88},{89,90,91,92},{93,94,95,96},{97,98,99,100}}, {{101,102,103,104},{105,106,107,108},{109,110,111,112},{113,114,115,116}, {117,118,119,120}} } }; Let’s presume that … Read more

advertisement

Multidimensional Array in C Programming

This C Tutorial Explains Multidimensional Array in C Programming with Example(s). An array with more than one dimension is called a multidimensional array. Consider an example below, int hawks[5][3]; /* a two dimensional array */ int pieces[2][2][3]; /* a three dimensional array */ int overs[5][5][5][5]; /* a four dimensional array */ and so on. Let’s … Read more

advertisement

Character Array Initialization in C

This C Tutorial Explains Character Array Initialization in C with Example(s). We already know about how to declare and initialize arrays. In particular, character arrays aren’t any exception! Let’s take an example of character array, char name[] = {’c’, ‘h’, ‘r’, ‘i’, ‘s’, ‘t’, ‘o’, ‘p’, ‘h’, ‘e’, ‘r’}; Array ‘name’ contains 11 characters. While … Read more

advertisement

What is Incomplete Initialization in C Programming?

This C Tutorial Explains Incomplete Initialization in C Programming with Example(s). Let’s consider examples of incomplete initialization below, int jams[5] = {1, 2, 3, 4, 5, 6}; int hats[5] = {1, 2, 3, 4}; Notice that ‘jams’ is an array of 5 integers while we are trying to pack it with 6 integers. What will … Read more

advertisement

Static and Automatic Initialization of an Array in C

This C Tutorial Explains Static and Automatic Initialization of an Array in C with Example(s). Let’s recollect concept of automatic and static initialization from declaring and initializing a scalar variable, auto int i; /* auto keyword optional */ can be written as: int i; /* by default automatic */ What’s in ‘i’? When a variable’s … Read more

advertisement

How to Pass a 1D Array as a Function Arguments in C?

This C Tutorial Explains One-Dimensional Arrays as Function Arguments in C Language with Example(s). C is a modular programming language meaning that it allows us to organise large programs into self-contained modules called functions. Each function performs some dedicated task. For example, void copy_str(char *dstr, char *sstr) { for (*dstr++ = *sstr++ != ‘\0’) ; … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.