C Programming Answers
C Programming Answers
strlen(): Returns the number of characters in a string (excluding null character '\0').
strupr(): Converts all lowercase letters in a string to uppercase. (Not standard in GCC)
2) Write a C program to copy one string into another string using a predefined string
function.
#include <stdio.h>
#include <string.h>
int main() {
gets(source);
strcpy(destination, source);
return 0;
Example:
4) Explain directive.
Types:
Syntax: malloc(size);
#include <stdio.h>
int main() {
else
return 0;
#include <stdio.h>
#include <string.h>
int main() {
return 0;
Macro:
- No type checking
- Faster execution
Function:
- Compiled at runtime
#include <stdio.h>
#define PI 3.14
int main() {
float r = 5;
return 0;
}
11) Explain command line arguments with an example.
Example:
#include <stdio.h>
return 0;
#include <stdio.h>
int main() {
float p, r, t;
return 0;
14) Write a C program to swap two integers using pointer (Hint: use call by reference)
#include <stdio.h>
*a = *b;
*b = temp;
int main() {
int x = 5, y = 10;
swap(&x, &y);
return 0;
A dangling pointer is a pointer that points to a memory location that has been freed or no longer
valid.
Example:
int *ptr;
int x = 5;
ptr = &x;