hello guys...
pls help me in this....
i m new to this language...C

help me !

Recommended Answers

All 6 Replies

hello guys...
pls help me in this....
i m new to this language...C


Compose a program that directly displays the byte-sizes of the standard data types in C including:
char, short, int, unsigned int, long, unsigned long, float, double, long double, and void. Use the
sizeof() C function that accepts any data type or identifier as a parameter and returns an integer
describing the number of bytes used.
Sample statement showing the size of an int,
printf("The amount of memory used by an int is: %d bytes\n", sizeof(int));

help me !

1. Compose a program that directly displays the byte-sizes of the standard data types in C including:
char, short, int, unsigned int, long, unsigned long, float, double, long double, and void. Use the
sizeof() C function that accepts any data type or identifier as a parameter and returns an integer
describing the number of bytes used.
Sample statement showing the size of an int,
printf("The amount of memory used by an int is: %d bytes\n", sizeof(int));
2. Add to the above program statements to display:
– The size of an array and an array pointer.
Declare an array of 4 integer elements called myArray[ ]
Display sizeof(myArray[4]) – this displays the size of the array
and sizeof(myArray) – this displays the size of the array pointer
Question: Does the program know how "big" the array is?
– The size of an explicit pointer.
Declare in integer pointer (int *ptr)
Display sizeof(ptr) and sizeof(int *)
Question: Does the size of the pointer differ if the pointer is changed to a double ?


With the following code, don't forget to use correct prototyping when writing functions!
3. Factorial
Write a function called factorial().
This function accepts one int parameter (n) and returns an int value which is the result of calculating
n!. The value of 5-factorial or 5! = 1 * 2 * 3 * 4 * 5.
The factorial calculation must be done using a simple for-loop, do not use recursion.
Test your function with a call from main(). Use a few different values, along with 0! and 1! (they
should both = 1).
4. Sum the Digits
Write a function called sumDigits().
This function accepts one int parameter (n) and returns an int value which is the sum of the digits
that makeup n. A call to sumDigits(512) will return the value of 5 + 1 + 2. The function must
work with all values of n where n >= 0, if n < 0, sumDigits() returns 0.
Test your function with a call from main() using a few different values.
5. Sum the Array
Write the function sumArray().
This function accepts an array filled with doubles as a parameter as well as an int which is the
number of elements in the array. The function returns a double value which is the sum of all of
the values in the array.
Test your function with a call from main() using at least 3 different sized arrays each containing
different values (the same value should not be repeated in any of the arrays).

Try using(including) the limits.h header file into your program.

There is nothing in limits.h that will help in this assignment. You will need to use the sizeof operator to obtain byte sizes of data.

We're not here to do your homework for you. Please show that you've put some effort into doing these exercises on your own.

sizeof() is used to calculate the sizes of datatypes, in number of bytes.

It returns the size of the type of the variable or parenthesized type-specifier that it precedes as a size_t type value. sizeof can be applied to all datatypes, be they primitive types such as the integer and floating-point types defined in the language, pointers to memory addresses, or the compound datatypes (unions, structs, or C++ classes).

for eg.

printf("%d",sizeof(char));

will return the size occupied by int in memory i.e., 1 byte.
similarly you can do for others .
Do the coding part and if still there is a problem , we are there for you to help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.