c programming 2017

2nd Semester

Year 2017

2.Write a program to add four integer taken from user
 

3. Explain dynamic memory allocation with example
The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime.
Dynamic memory allocation in c language is possible by 4 functions of stdlib.h header file.
malloc():-allocates single block of requested memory.
The syntax of malloc() function is given below:
ptr=(cast-type*)malloc(byte-size)
calloc():-allocates multiple block of requested memory.
The syntax of calloc() function is given below:
ptr=(cast-type*)calloc(number, byte-size)
realloc():-reallocates the memory occupied by malloc() or calloc() functions
ptr=realloc(ptr, new-size)
free():-frees the dynamically allocated memory
The syntax for free() function is given below:
free(ptr)
Program to for dynamic memory allocation

4.List and explain different file opening modes
A file represents a sequence of bytes on the disk where a group of related data is stored.File is created for permanent storage of data. It is a ready-made structure.The fopen() function is used to create a new file or to open an existing file.
Different modes in file handling.

S.N Modes and Description
1 “r”: Opens a file for reading. The file must exists
2 “w”: Creates an empty file for writing. If a file with same name already exists, its content is erased and the file is considered as a new empty file.
3 “a”: Appends to a file. Writing operations append data at the end of file. The new file is created if it does not exist.
4 “r+”: Opens a file to update both reading and writing. The file must exist
5 “w+”: Creates an empty file for both reading and writing
6 “a+” :Opens a file for reading and appending

5.Write a function to check whether a given number is 987 or not





6. Write a function to copy content of one array to another array. You can consider any type of arrays.

Group “C”

7.List any five string handling functions. Write a program to swap contents of two string variables with each other.
The five string handling functions are:

  • strlen():- This function is used to find length of string
  • strcmp():-This function is used to compare two strings
  • strcpy():-This function is used to copy one string into another
  • strrev():- This function is used to reverse the content of string
  • strlwr():- This function is used to convert uppercase into lowercase

8.Write a program to print following pattern using for loop
2
4
8
14
22

9. Write a program to store value of two integer variables in a file named “Two_Rupees.txt.

1 thought on “c programming 2017

Leave a Reply

Your email address will not be published.