C&PP 2marks
C&PP 2marks
1. What will be the values for argc and argv[] when the input “run with my values” is
passed as command line arguments?
argc = 4
argv values:
o argv[0] = "run"
o argv[1] = "with"
o argv[2] = "my"
o argv[3] = "values"
Opens a file with the specified mode like "r", "w", "a", etc.
4. Write a C program to get name and marks of n number of students from user and store
them in a file.
#include <stdio.h>
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
fclose(f);
return 0;
Execution:
Ravi 88.50
Kavi 92.00
5. Outline the logic to swap the contents of two identifiers without using a third variable.
int a = 5, b = 10;
a = a + b;
b = a - b;
a = a - b;
Output:
a = 10, b = 5
s = "hello"
print(s.upper()) # HELLO
print(s[1:4]) # ell
print(s * 2) # hellohello
Case-sensitive.
a = True
b = False
print(a or b) # True
print(not a) # False
bool, str
10. Name any two functions used in Random Access files and specify their use in C
Programming.
char str[50];
FILE *f = fopen("sample.txt", "r");
fclose(f);
f = fopen("output.txt", "w");
fclose(f);
12. What will be the impact if fclose() function is avoided in a file handling C program?
13. Write a C Program to Copy one file content into another file.
#include <stdio.h>
int main() {
char ch;
fputc(ch, dest);
fclose(src);
fclose(dest);
return 0;
Input (source.txt):
Advanced C Programming
Output (copy.txt):
Advanced C Programming
for i in range(5):
if i == 2:
continue
print(i)
Output:
i=1
while i <= 3:
print(i)
i += 1
Output:
3
17. Comment with an example on the use of local and global variable with the same
identifier name.
def func():
x = 50 # Local variable
print("Local x:", x)
func()
print("Global x:", x)
Output:
Local x: 50
Global x: 100
s = "Welcome"
print(s.upper()) # WELCOME
print(s.lower()) # welcome
print(s.find("co")) # 3