Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


C Programming Code Examples

Learn C Language

sizeof() Operator in C Programming Language

sizeof() Operator in C
The sizeof() operator is commonly used in C. It determines the size of the expression or the data type specified in the number of char-sized storage units. The sizeof() operator contains a single operand which can be either an expression or a data typecast where the cast is data type enclosed within parenthesis. The data type cannot only be primitive data types such as integer or floating data types, but it can also be pointer data types and compound data types such as unions and structs.
Syntax for sizeof() Operator in C
#include <stdio.h> sizeof (data type)
data type
Where data type is the desired data type including classes, structures, unions and any other user defined data type. Mainly, programs know the storage size of the primitive data types. Though the storage size of the data type is constant, it varies when implemented in different platforms. For example, we dynamically allocate the array space by using sizeof() operator:
/* return the size of a variable by sizeof() operator example */ int main( int argc, char* argv[] ) { printf("sizeof(char) = %d\n", sizeof(char) ); printf("sizeof(short) = %d\n", sizeof(short) ); printf("sizeof(int) = %d\n", sizeof(int) ); printf("sizeof(long) = %d\n", sizeof(long) ); printf("sizeof(long long) = %d\n", sizeof(long long) ); printf("\n"); printf("sizeof(unsigned char) = %d\n", sizeof(unsigned char) ); printf("sizeof(unsigned short) = %d\n", sizeof(unsigned short) ); printf("sizeof(unsigned int) = %d\n", sizeof(unsigned int) ); printf("sizeof(unsigned long) = %d\n", sizeof(unsigned long) ); printf("\n"); printf("sizeof(float) = %d\n", sizeof(float) ); printf("sizeof(double) = %d\n", sizeof(double) ); printf("sizeof(long double) = %d\n", sizeof(long double) ); printf("\n"); int x; printf("sizeof(x) = %d\n", sizeof(x) ); }

C various file opening modes: File is opened using fopen() c function, while opening you can use any of the following mode as per the requirement. Mode "r": It is a read only mode,





C program Read two strings and Concatenate them, without using library functions. Display the 'Concatenated String'. Take two strings as input and store them in the arrays string1 and

C language encrypting and decrypting files. So as to change enter file path. Enter password. Open a file to store decoded data. Until end of file to be encrypted read each...