0% found this document useful (0 votes)
302 views33 pages

PPS All Units 2 MarksQuestions With Answers

The document contains multiple choice questions related to C programming concepts like data types, operators, loops, arrays, strings etc. It provides the questions along with the correct answers. Some questions have output to be evaluated for given code snippets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
302 views33 pages

PPS All Units 2 MarksQuestions With Answers

The document contains multiple choice questions related to C programming concepts like data types, operators, loops, arrays, strings etc. It provides the questions along with the correct answers. Some questions have output to be evaluated for given code snippets.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Match the following:

Data Type Format Specifier


1.int A.%c
2.float B.%s
3.str C.%f
4.char D.%d

1 -- D
2 -- C
3 -- B
4 -- A
All Operating Systems get their total memory initialized from ______________
RAM
Match the following:
Data Type Size in bytes
1. int A. 4
2. char B. 8
3. float C. 2
4. double D. 1

1– C
2–D
3–A
4 -- B
Match the following:
Variable Type Meaning
1. Character A. double precision floating point numbers
2. Integer B. floating point numbers
3. Double C. signed whole numbers
4. Float D. character data

1–D
2–C
3–A
4–B
Process, task, action, operation instructions in flowchart are represented in __________ symbol.
Rectangle
_________________box symbol that can represent two different conditions in a flow chart.
Parallelogram
____________ converts the programs written in assembly language into machine instructions.
Assembler

A program that can execute high-level language programs is called _________________


Compiler
Can I use `int` data type to store the value 32768? Give YES or NO and justify the answer with a one line
description.
YES for 32 Bit Compiler, NO for 16Bit Compiler
The String data type is an extension of the __________ data type
Character
Match the following:
Tokens Examples
1. Keywords A. +, /
2. Operators B. 10, 20
3. Constants C. main, total
4. Identifiers D. int, while

1–D
2–A
3–B
4–C
What is the output of this C code?
int main()
{
int var = 010;
printf("%d", var);
}

8 is the Answer because 010 0represents Octal. Octal 10 = Decimal 8

What is the output for the following code?


#include <stdio.h>
void main() {
int a = 10, b = 5, c = 5;
int d;
d = (a == (b + c));
printf("%d", d);
}

1
What is the output for the following code?
#include <stdio.h>
void main() {
int x = 10;
printf("%d %d %d\n", x <= 10, x == 40, x >= 10);
}

101
What is the output of the code given below?
#include <stdio.h>
void main() {
int a = 10, b = 5, c = 3;
b = !a;
c = !!a;
printf("%d %d", b, c);
}
a =10 it is true, not(true) = false, hence b = 0
c =10 it is true, not(true) = false , not (false) = 1
What is the output of the code given below?
#include<stdio.h>
void main() {
int i = 10;
i = ((!(i > 14)) || (i < 8));
printf("i = %d", i);
}

What is the output of the below program?


#include <stdio.h>
int main()
{
int son = 18;
int father = 40;
int age;
age = son > father ? son : father;
printf("%d is the age",age);
return 0;
}

40
What is the output of the below program?
#include <stdio.h>
int main()
{
int x=1, y ;
y = ( x ==1 ? 2 : 0 ) ;
printf("x value is %d\n", x);
printf("y value is %d", y);
}

X value is 1
Y value is 2
Evaluate the output
void main()
{
int i=2,j=2;
while(i+1?--i:j++)
printf("%d",i);
}

1
Match the following:
Header File Operations
1.#include<stdio.h> A. clrscr()
2.#include<conio.h> B. sqrt() and pow()
3.#include<math.h> C. malloc()
4.#include<stdlib.h> D. scanf() and printf().

1–D
2–A
3–B
4 -- C

int main()
{
int x = 19;
printf ("x << 1 = %d\t", x << 1);
printf ("x >> 1 = %d\n", x >> 1);
return 0;
}
What is the output of the program?

X << 1 = 38
X >> 1 = 9

Find the output for `0110 & 1100`.

0100
Consider the following C program:
# include <stdio.h>
int main( )
{
int i, j, k = 0;
j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
k –= - -j;
for(i = 0; i < 5; i++)
{
switch(i + k)
{
case 1:
case 2: printf(“\n%d”, i + k);
case 3: printf(“\n%d”, i + k);
default: printf(“\n%d”, i + k);
}
}
return 0;
}
The number of times printf statement is executed is __________.

10 Times

-1 When (i+k) =-1 default case will be printed


0 When (i+k) = 0 default case will be printed
1 When (i+k) = 1 case 1, case 2, case 3 and default case will be printed
1
1
2 When (i+k) = 2 case 2, case 3 and default case will be printed
2
2
3 When (i+k) = 3 case 3 and default case will be printed
3
int x=2;
x*=3+2;
After the execution of above statement x will have the value
x= 2 * 5
= 10
Arrange the operators according to their precedence `+, %, ->, =` from highest to lowest priority.
->
%
+
=
What is the output of the following C code
#include<stdio.h>
void main()
{
int a=5*3+2-4;
printf(“%d”,a);
}

13

Find the output for the following code:


#include <stdio.h>
int main()
{
int x = 1;
if (x = 0)
printf("MVGR");
else
printf("MVGRCE");
}

MVGR

Find the output for the following


main()
{
int a = 1;
if (a--)
printf("True");
if (a++)
printf("False");
}

In 1st if is True (a is having some value(post decrement)) hence True will be printed.
In 2nd if false (a is 0, (post increment)) hence false will not be printed.
Find the output for the following
char ch = 'A';
switch (ch)
{
case 'A' :
printf ("choice A \n") ;
case 'B' :
printf ("choice B ") ;
case 'C' :
case 'D' :
case 'E' :
default:
printf ("No Choice") ;
}
choice A
choice B No Choice
Find the output for the following
#include<stdio.h>
void main()
{
int x=0;
if(x==0)
printf(“true,”);
else if(x=10)
printf(“false, ”);
printf(“%d\n”,x);
}

true, 0
Find the correct output for the following code:
#include <stdio.h>
int main()
{
int i = 0, j = 0;
while (i<5,j<10)
{
i++;
j++;
}
printf("%d %d", i, j);
}

10 10
Because (,) operator has right to left associativity. Hence J will be evaluated 10 times
Find the correct output for the following code:
#include <stdio.h>
void main()
{
int var=1;
while (var <=2)
{
printf("%d ", var);
}
}
Indefinite loop as var is not incremented
What is the output for the following code:
#include <stdio.h>
void main()
{
int cnt=1;
do
{
printf("%d,",cnt);
cnt+=1;
}while(cnt>=10);
printf("\nAfter loop cnt=%d",cnt);
printf("\n");
}
1,
after loop cnt = 2
because do loop will be executed only once.
Find the output of the following code:
#include <stdio.h>
void main()
{
int i=0;
char c=’0’;
do
{
printf(“%c”,c+i);
++i;
}while(i<5);
}
01234
Because character 0 (ASCII) + ASCII of I (int) will be evaluated
Find the output for the following code:
#include <stdio.h>
int main()
{
int n;
for (n = 9; n != 0; n--)
printf("%d", n--);
}

Indefinite loop

In the following loop construct, which one is executed only once always.
for(exp1; exp2; exp3)

Exp1 as in for loop initialization part will be executed only once


Can `break` statement be used within an if block if it is not nested inside a looping construct or a
`switch` construct? Answer YES or NO.

Find the output of the following C code?


void main()
{
int i=0;
for(i=0;i<5;i++)
if(i<4)
{
printf(“Hello”);
break;
}
}
Hello will be printed only once
Find the output for the following:
#include <stdio.h>
void main()
{
int i = 0, j = 0;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 1;)
{
break;
}
printf("MVGR \n");
}
}
MVGR
MVGR
MVGR
MVGR
MVGR

In I loop MVGR will be printed five times


Find the output of the following:
#include <stdio.h>
int main()
{
int count=1;
while (count <= 4)
{
printf("%d ", count);
count++;
}
return 0;
}
1234
What will be the output of the following C code?
#include <stdio.h>
void main()
{
int a[2][3] = {1, 2, 3, 4, 5};
int i = 0, j = 0;
for (i = 0; i < 2; i++)
for (j = 0; j < 3; j++)
printf("%d", a[i][j]);
}
1 2 3 4 5 0 Because in 2D array column size is 3, hence 3rd element in the 2nd row will be initialized to 0
___________is output of following program?
main()
{
int a[7]={11,12,13,14,15,16,17};
int i;
printf(“content of array”);
for(i=0;i<=6;++i);
{
printf(“%d\t”,a[i]);
}
}

Content f array7 as for loop is having semicolumn;


_____________will be the output of the following program?
void main( )
{
int x []= {10,20,30,40,50};
printf (“ \n %d %d %d %d “, x [4] ,3[x] ,x[2] ,1[x] ,x[0] );
}

50 40 30 20 as only four format specifiers have to be printed (%d %d %d %d)


Here 3[x] will be treated as x[3] and 1[x] will be treated as x[1]
What will be the output of following program ?
#include <stdio.h>
int main()
{ static int x[]={'A','B','C','D','E'},tally;
for(tally=0;tally< sizeof(x)/sizeof(int) ; tally+=1)
printf("%c,%c,%c\n",*(x+tally)+1,x[tally]+1,*(tally+x)+1);
return 0;
}
B,B,B
C,C,C
D,D,D
E,E,E
F,F,F
_________ will be the output of the program ?
#include<stdio.h>
int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}

3, 2, 15
Consider the following program fragment
void main()
{
int s[ ][2]={2,4,1,3};
int sum= 0, j=0, I;
for (int i=0;i<2;i++,j++)
{
sum=sum+(s[i][j]+i+j);
}
printf(“%d”, sum);
}
The above program prints-------------
7
consider the following c program
void main ()
{
Char CA[ ]={ ‘a’, ’\t’, ’b’, ’\n’, ‘c’, ‘\0’};
Char *p,*p1;
p=&CA[3];
p1=CA;
printf(“%d” ,+ +*p+ ++*p1-20};
}
The output of the above c program should be _____________
It gives the compilation error as printf() statement ended with }

What is the output of the following C code?


#include <stdio.h>
int main()
{
char *str = "hello, world";
char str1[15] = "hello wo 9";
strcpy(str, str1);
printf("%s", str1);
}
What will be the output for the following code?
void main ( )
{
char a[] = “INFO” ;
a + +;
printf (“ \n %s”, a); }

Compilation error at a + +;
Consider the following program fragment
#include<stdio.h>
int main()
{
float arr[] = {12.4, 2.3, 4.5, 6.7};
printf("%d\n", sizeof(arr)/sizeof(arr[0]));
return 0;
}
The above program prints-------------
4 as the size of float is 4
What is the output for the below C code
#include <stdio.h>
#include <string.h>
void main(void) {
char strbuffer[8] = "bbbbbbb";
char str1[] = "Hello World";
str1[3] = '\0';
strcpy(strbuffer, str1);
printf("%s\n",strbuffer);
}
Hel
as str1[3]=’\0’
What is the output for the below C code?
#include <stdio.h>
#include <string.h>
void main(void) {
char str1[] = "Godavari";
char str2[20];
char str3[] = "River";
int i;
i = strcmp(strcat(str3, strcpy(str2, str1)), "RiverGodavari");
printf("%d\n", i);
}
0 as both strings are equal

What will be the output of the following C code?


#include <stdio.h>
int main()
{
char *str = "hello, world";
char str1[15] = "hello wo 9";
strcpy(str, str1);
printf("%s", str1);
}
Consider the following C program segment:
char p[20];
char *s = "string";
int length = strlen(s);
int i;
for (i = 0; i < length; i++)
p[i] = s[length — i];
printf("%s", p);
A language with string manipulation facilities uses the following operations. head(s)- returns the first
character of the string s tail(s)- returns all but the first character of the string s concat(sl, s2)-
concatenates string s1 with s2. The output of concat(head(s), head(tail(tail(s)))), where s is acbc is--------
-----
abcd
What will be the output of the following C code?
#include <stdio.h>
int main()
{
char *str = "hello, world";
char *str1 = "hello, world";
if (strcmp(str, str1))
printf("equal");
else
printf("unequal");
}
unequal
because strcmp() returns 0 due to both strings are equal. Hence if statement false part will be printed.
What is the worst case time complexity of insertion sort where position of the data to be inserted is
calculated using binary search?
N^2
Applying binary search to calculate the position of the data to be inserted doesn’t reduce the time
complexity of insertion sort. This is because insertion of a data at an appropriate position involves two
steps:
1. Calculate the position.
2. Shift the data from the position calculated in step #1 one step right to create a gap where the data
will be inserted.

Using binary search reduces the time complexity in step #1 from O(N) to O(logN). But, the time
complexity in step #2 still remains O(N). So, overall complexity remains O(N^2).
What will happen if in a C program you assign a value to an array element whose subscript exceeds the
size of array?
The program may crash if some important data gets overwritten. But modern C compilers will take care
of thiskind of errors. (Ex:gcc)
What is the output for the below C code?
#include <stdio.h>
void main() {
char p[] = "%d\n";
p[1] = 'c';
printf(p, 66);
}
B
What is the output for the below C code
#include <stdio.h>
#include <string.h>
void main(void) {
char strbuffer[8] = "bbbbbbb";
char str1[] = "Hello World";
str1[3] = '\0';
strcpy(strbuffer, str1);
printf("%s\n",strbuffer);
}
Hel
Which sorting algorithm will take least time when all elements of input array are identical? Consider
typical implementations of sorting algorithms.
The insertion sort will take O(n) time when input array is already sorted.
Consider a situation where swap operation is very costly. Which of the following sorting algorithms
should be preferred so that the number of swap operations are minimized in general?
Selection Sort
Assume that we use Bubble Sort to sort n distinct elements in ascending order. When does the best
case of Bubble Sort occur?
When elements are sorted in ascending order
Consider the array A[]= {6,4,8,1,3} apply the insertion sort to sort the array . Consider the cost
associated with each sort is 25 rupees , what is the total cost of the insertion sort when element 1
reaches the first position of the array ?
Rs. 50.00
When the element 1 reaches the first position of the array two comparisons are only required hence 25
* 2= 50 rupees.
step 1: 4 6 8 1 3 .
step 2: 1 4 6 8 3.
The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 5, 13 in ascending order, using
bubble sort is_______
10 times
What is the output of the following code?
#include <stdio.h>
int main()
{
int x = 10;
static int y = x;

if(x == y)
printf("Equal");
else if(x > y)
printf("Greater");
else
printf("Less");
return 0;
}
It gives compilation error. Because static int y canot be initialized with another variable. It has to be
initialized with constant value only.
A newspaper route has recently been computerized. Information about each of the 100 customers is
stored in individual records containing first name, last name, and payment due. In writing a computer
program to process the customer records, the programmer is uncertain whether to add a procedure to
sort the records. If the records are first sorted, what will be the maximum number of comparisons
needed with a binary search to find a particular customer's record?
7

What is the output of following program?


#include <stdio.h>
int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}
0000
Because after calling main() printf() is there by that time value of I becomes 0
what is the output of the following program
#define square(x) x*x
main()
{
printf(“%d”,64/square(4));
}
64
If we write #define square(x) (x *x), then we will get 4 (64/16)
What will the SWAP macro in the following program be expanded to on preprocessing? will the code
compile?
#include<stdio.h>
#define SWAP(a, b, c)(c t; t=a, a=b, b=t)
int main(){

int x=10, y=20;


SWAP(x, y, int);
printf("%d %d\n", x, y);
return 0;
}
No it will not compile. Int can’t be variable or const name.
What is the output for this program and justify
#define clrscr() 100
main(){
clrscr();
printf("%d\n",clrscr());
}
It prints 100 because clrscr()is substituted with 100 (Macro)
What is the output for this program and justify
main()
{
extern int i;
i=20;
printf("%d",i);
}
It gives an compilation error. Because I has to be declared out side of main() then only we can declare
extern int I;

What is the output for this program and justify


main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}
54321
Because static makes var to retain its value during function calls

Describe in one line what actions does return statement perform or initiate?
The return statement returns the flow of the execution to the function from where it is called. This
statement does not mandatorily need any conditional statements. As soon as the statement is
executed, the flow of the program stops immediately and return the control from where it was called.
What is the output of following code
#include<stdio.h>
void main() {
int a=5, b=10;
{
int a = 10; int b=a+b;
a=a+b;
}
printf("a = %d b=%d\n",a, b);
}
a = 5 b=10
due to blockscope.
Write the output of the follwing code:
#include<stdio.h>
int a=10, b=5;
void main() {
int a=15;
b=10;
b=a+b;
a=a+b;
printf("in main function: a = %d b=%d\n",a, b);
add();
}
void add() {
printf("In add function a=%d, b=%d\n", a, b);
}
in main function: a = 40 b=25
In add function a=10, b=25
Match the Following:
a) Duplicate Copy of Original Parameter is Passed 1. Call by
reference
b) Actual Copy of Original Parameter is Passed 2. Call by
reference
c) Original Parameter gets affected if value of parameter changed inside function 3. Call by value
d) No effect on Original Parameter after modifying parameter in function 4. Call by value
A 3
B1
C 2
D 4
In function call arguments are called as ___________________ , in function declaration arguments are
called as _____________________
i) Actual parameters ii) Formal parameters
What is the output of this C code?
int main()
{
void foo(), f();
f();
}
void foo()
{
printf("2 ");
}
void f()
{
printf("1 ");
foo();
}
12
What will be the output of the following C code?
#include <stdio.h>
void main()
{
static int x = 3;
x++;
if (x <= 5)
{
printf("hi");
main();
}
}
hihi
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int i = 10;
int *p = &i;
foo(&p);
printf("%d ", *p);
printf("%d ", *p);
}
void foo(int **const p)
{
int j = 11;
*p = &j;
printf("%d ", **p);
}
11 11 and address
Match the Following:
a) Duplicate Copy of Original Parameter is Passed 1. Call by
refernce
b) Actual Copy of Original Parameter is Passed 2. Call by refence
c) Original Parameter gets affected if value of parameter changed inside function 3. Call by value
d) No effect on Original Parameter after modifying parameter in function 4. Call by value

A3
B1
C2
D 4
What will be the output of the following?
#include <stdio.h>
int main(void) {
int num = 10;
int *ptr1 = &num;
int *ptr2;
int *ptr3=0;
if(ptr1 == 0)
printf("ptr1: NULL\n");
else
printf("ptr1: NOT NULL\n");
if(ptr2 == 0)
printf("ptr2: NULL\n");
else
printf("ptr2: NOT NULL\n");
if(ptr3 == 0)
printf("ptr3: NULL\n");
else
printf("ptr3: NOT NULL\n");
return 0;
}
ptr1: NOT NULL
ptr2: NOT NULL
ptr3: NULL
What is the output for the below C code?
#include <stdio.h>
int rec(int num) {
return (num) ? num % 10 + rec(num / 10) : 0;
}
void main() {
printf("%d",rec(4567));
}
22
What is the output for the below C code?
#include <stdio.h>
void main() {
int i = 3, *j, **k;
j = &i;
k = &j;
printf("%d %d %d", *j, **k, *(*k));
}
3 3 3
What is the output of the following code?
#include<stdio.h>
int main(){
int a, b, c;
char *p = 0;
int *q = 0;
double *r = 0;
a = (int)(p + 1);
b = (int)(q + 1);
c = (int)(r + 1);
printf("%d %d %d",a, b, c);
return 0;
}
1 4 8
Predict the output:
#include <stdio.h>
int main()
{
float arr[5] = {12.5, 10.0, 13.5, 90.5, 0.5};
float *ptr1 = &arr[0];
float *ptr2 = ptr1 + 3;
printf("%f ", *ptr2);
printf("%d", ptr2 - ptr1);
return 0;
}
90.500000 3
Predict the output:
#include<stdio.h>
void main() {
int a[5]={1,2,3}, i;
for(i=0;i<5;i++)
printf("%d",*(a+i));
}
12300
What is the output of C program with arrays and pointers.?
#include<stdio.h>
int main()
{
int a[3] = {20,30,40};
printf("%d", *(a+1));
}
30
What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s;
printf("%c\t%c", p[0], s[1]);
}
h e
What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *s= "hello";
char *p = s;
printf("%c\t%c", 1[p], s[1]);
}
e e
What is the output of C program with arrays and pointers.?
int main()
{
int size=4;
int a[size];
a[0]=5;a[1]=6;
a[2]=7;a[3]=8;
printf("%d %d", *(a+2), a[1]);
}
76
What would be the equilant pointer expression for referring the array element a[i][j][k][l]
****ptr;
Predict the output:
#include<stdio.h>
int main()
{
char *colleges[] = {"MVGR", "GVP", "ANITS"};
int **i = &colleges[0];
printf("%c\n", **i);
return 0;
}
M as **I points to 1st character of 1st row
What will be the output for the following code?
#include<stdio.h>
int main()
{
int a = 10;
void *ptr = &a;
printf("%d", *(int *)ptr);
return 0;
}
10
What will be the output for the following code?
#include<stdio.h>
int main()
{
int a = 10;
void *ptr = &a;
printf("%d", *ptr);
return 0;
}
It gives compilation error. Because the pointer is void. While printing we have to type cast the pointer
as
printf(“%d”,(int *) *ptr);
What is the number of moves required to solve Tower of Hanoi problem for n disks?

2n-1

Predict the output:


main(){
int a=10, *p;
p=&a;
printf("%u %d",p,*p);
}

In the bellow function call a nd b are passed with addresses of a and b respectyively.
Write the correct definition of the function.
int a=10,b=20;
int c=add(&a, &b);

void add(int *x, int *y) {


int z;
z = *x + *y;
return z;
}

What is the syntax of CALLOC to allocate memory to an array at runtime.?


*ptr = ( data_type *) calloc(int number, sizeof(var));
__________ will be the output of the following C code?
#include <stdio.h>
struct p
{
int k;
char c;
};
int p = 10;
int main()
{
struct p x;
x.k = 10;
printf("%d %d\n", x.k, p);
}

10 10

What will be the output of the following C code ________


#include <stdio.h>
struct student
{
int no;
char name[20];
}
void main()
{
struct student s;
s.no = 8;
printf("hello");
}

struct student
{
int no;
char name[20];
} is not ended with semicoloumn (;) Hence it gives compilation error
otherwise it will print hello
_________ will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
foo(p1);
}
void foo(struct point p[])
{
printf("%d\n", p[1].x);
}
3

________ will be the output of the following C code?


struct employee{
int empId;
char *name;
int age;
};
int main()
{
struct employee emp []={ {1,"Mike",24}, {2,"AAA",24}, {3,"BBB",25}, {4,"CCC",30} };

printf("Id : %d, Age : %d, Name : %s", emp[2].empId,3[emp].age,(*(emp+1)).name);


return 0;
}
Id : 3, Age : 30, Name : AAA
______ will be the output of the following C code?
#include <stdio.h>
struct temp
{
int a;
} s;
void func(struct temp s)
{
s.a = 10;
printf("%d\t", s.a);
}
main()
{
func(s);
printf("%d\t", s.a);
}
10 0
______ will be the output of the following C code?
#include <stdio.h>
struct student
{
char *c;
};
void main()
{
struct student m;
struct student *s = &m;
s->c = "hello";
printf("%s", s->c);
}
hello

What will be the output of the following C code ____________


#include <stdio.h>
typedef struct student
{
char *a;
}stu;
void main()
{
struct student s;
s.a = "hey";
printf("%s", s.a);
}
hey
What is the output of C program.?
int main()
{
struct ship
{
int size;
char color[10];
}boat1, boat2;
boat1.size=10;
boat2 = boat1;
printf("boat2=%d",boat2.size);
return 0;
}
Boat2=10
___________ is the output for the following code?
main() {
struct book
{
int pages;
char name[10];
}a;
a.pages=10;
strcpy(a.name,"Cbasics");
printf("%s=%d", a.name,a.pages);
}
Cbasics=10
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *name;
};
struct student s;
struct student fun(void)
{
s.name = "newton";
printf("%s\n", s.name);
s.name = "alan";
return s;
}
void main()
{
struct student m = fun();
printf("%s\n", m.name);
m.name = "turing";
printf("%s\n", s.name);
}
Newton
Alan
Alan

What will be the output of the following C code?


#include <stdio.h>
struct student
{
char *name;
};
void main()
{
struct student s, m;
s.name = "st";
m = s;
printf("%s%s", s.name, m.name);
}
stst
What will be the output of the following C code?
#include <stdio.h>
typedef struct p *q;
struct p
{
int x;
char y;
q ptr;
};
int main()
{
struct p p = {1, 2, &p};
printf("%d\n", p.ptr->ptr->x);
return 0;
}
1
What will be the output of the following C code?

#include <stdio.h>
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student m;
s.c = m.c = "hi";
m.point = &s;
(m.point)->c = "hey";
printf("%s\t%s\t", s.c, m.c);
}

hey hi
What will be the output of the following C code?

#include <stdio.h>
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
printf("%d", sizeof(s));
}
8
What will be the output of the following C code?

#include <stdio.h>
struct p
{
int x;
int y;
};
int main()
{
struct p p1[] = {1, 2, 3, 4, 5, 6};
struct p *ptr1 = p1;
printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
}
15

What will be the output of the following C code?

#include <stdio.h>
struct p
{
int x;
char y;
};
int main()
{
struct p p1[] = {1, 92, 3, 94, 5, 96};
struct p *ptr1 = p1;
int x = (sizeof(p1) / sizeof(struct p));
printf("%d %d\n", ptr1->x, (ptr1 + x - 1)->x);
}
15
What is the output of C program.?
int main()
{
struct book
{
int pages;
char name[10];
}a;
a.pages=10;
strcpy(a.name,"Cbasics");
printf("%s=%d", a.name,a.pages);
return 0;
}
Cbasics =10
The following code will open file in ______________ mode
FILE *fp;
fp = fopen("demo.txt", "rb");

binary
#include<stdio.h>
int main(){
FILE *fp;
char *str;
fp=fopen("demo.txt","r");
//demo.txt :you are a good programmer
while(fgets(str,6,fp)!=NULL)
puts(str);
fclose(fp);
return 0;
}
will give the output_________________
you a
re a
good
progr
ammer
#include<stdio.h>
void fun(int);
int main(int argc)
{
printf("%d ", argc);
fun(argc);
return 0;
}
void fun(int i)
{
if(i!=4)
main(++i);
} ___________________is the output of the above code

1234

You might also like