Professional Documents
Culture Documents
Q. Find The Error Char s1 "PES" Char s2 (4) s2 s1 s2 (0) 'M' Printf ("%S", s1)
Q. Find The Error Char s1 "PES" Char s2 (4) s2 s1 s2 (0) 'M' Printf ("%S", s1)
char s1[]=”PES”;
char s2[4];
s2=s1;
s2[0]=’M’;
printf(“%s”, s1);
Answer: The error in the code is the assignment s2 = s1. In C, arrays cannot be assigned using
the assignment operator ( =). Instead, you need to use string manipulation functions like strcpy
to copy the contents of one array into another.
q. predict output
int main(){
printf("%d", ++3);}
Answer: The expression ++3 is not valid in C. The ++ operator is used to increment the
value of a variable, but it cannot be used with a constant or a literal.
In the line printf("%d", ++3);, the code attempts to increment the value of the
constant 3. However, this is not allowed in C and will result in a compilation error.
Q. Predict output
printf("%d", -1?0:1);
Q. WRITE PROGRAM THAT COUNTS characters and words from a line input from
user
Answer:
Q. find second largest element of an array
Q. Predict output
Int main(){
Int a[6] = {77,22,34,66,99};
Int *b=a;
Printf(“%d”, a[5]);
Printf(“%d”, ++*b);
Printf(“%d”, (*c)++);
Return 0;}
The array a is declared with a size of 6 but initialized with only 5 elements.
a[5] would lead to potential issues accessing uninitialized memory.
Q. given two strings, write a program to count every letter of str1 in str2
Q. write a c program to display list of students in 6th semester. Student struct has name,
id and semester fields
Q.
Struct car
Int year;
Char company[100];
Write c program to create a pointer to structure, allocate memory and assign values of
members using the pointer
Answer:
Q. What is the output
The struct Binary is defined with two bit fields: a with 2 bits and b with 4 bits.
The union Ternary is defined with three members: a and b of type int and c as
a character array of size 100.
In the main function, a variable b of type struct Binary is declared.
The value 16 is assigned to b.b.
Since the bit field b in struct Binary is defined with 4 bits, it can store values from 0 to 15.
Assigning the value 16 to b.b may lead undefined behavior.
Offset of the member c within union Ternary. In a union, all members share the same
memory space, so the offset of each member within the union will be 0.
Q. Write output
In the enum city, the identifiers Bangalore, Mysore, Mangalore, and Pune are
assigned values 0, 5, 6, and 7 respectively.
The first printf statement prints the values of Mysore and Bangalore, which are
5 and 0 respectively.
The variable c is assigned the value Pune from the enum city.
The second printf statement performs arithmetic operations using c and
Mysore. c * Mysore evaluates to 7 * 5 = 35, and c / Mysore evaluates to 7 /
5=1
Q. Predict output