0% found this document useful (0 votes)
17 views

C Programs

This program uses the malloc function to allocate memory for a struct variable and prints the size of the struct which is 8 bytes. It correctly allocates and prints the size.

Uploaded by

Sathya Ashok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

C Programs

This program uses the malloc function to allocate memory for a struct variable and prints the size of the struct which is 8 bytes. It correctly allocates and prints the size.

Uploaded by

Sathya Ashok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

This program will allocate the


memory of ___ bytes for pointer “ptr”.
3. What is the output of this program?
#include<stdio.h>
#include<stdlib.h> #include<stdio.h>
#include<stdlib.h>
int main() struct st{
{ int a;
int *ptr; char b;
ptr = realloc(0,sizeof(int)*10); };
return 0;
} int main()
{
struct st *st_ptr;
a)0 st_ptr =
b)10 malloc(sizeof(struct st));
c)40 printf("%d\n",sizeof(struct st));
d)none of the mentioned return 0;
Answer: c }

2. What is the output of this program? a)8


b)5
#include<stdio.h> c)0
#include<stdlib.h> d)none of the mentioned
Answer: a
int main()
{
char *ptr;
free(ptr);
return 0
}
a) this program will print nothing after
execution
b)segmentation fault
c)Aborted (core dumped)
d)none of the mentioned
Answer: c
4.Point out the error in the program?
5..Point out the compile time error in the
program given below.
#include<stdio.h>
#include<stdlib.h>
#include<stdio.h>
int main()
{ int main()
unsigned char; {
FILE *fp; int *x;
fp=fopen("trial", "r"); *x=100;
if(!fp) return 0;
{ }
printf("Unable to open file");
exit(1);
} OPTIONS:
fclose(fp);
return 0; A) Error: invalid assignment for x
} B) Error: suspicious pointer
conversion
C) No error
D) None of above
OPTIONS: Answer: Option C
A) Error: in unsigned char statement
B) Error: unknown file pointer
C) No error
D) None of above
Answer: Option C
6.What will be the output of the
program?

#include<stdio.h>
int main()
{
float a=0.7;
if(a < 0.7)
printf("C\n"); 7.Point out the error in the program?
else
printf("C++\n");
return 0; #include<stdio.h>
}
int main()
OPTIONS: {
int a[] = {10, 20, 30, 40, 50};
A) C
int j;
B) C++ for(j=0; j<5; j++)
C) Compiler error {
printf("%d\n", a);
D) Non of above a++;
Answer:A }
return 0;
}

8.find out the error of the following


OPTIONS:
program.
A) Error: Declaration syntax
#include<stdio.h> B) Error: Expression syntax
int main() C) Error: LValue required
{ D) Error: Rvalue required
printf(‘hello world”) Answer: Option C
getch();
return 0;
}

OPTIONS:
A) “ and ‘ B) { and ‘ and return0
C) : and ; D) ” and ; and getch()
Answer: D
9.find out the error of the following
program:
10.find out the error of the following?
#include<stdio.h> #include<stdio.h>
#include<conio.h>
void main () Int main()
{ {
char s[20];
clrscr(); int num1,num2,sum:
printf(“enter the string?”); printf(“enter two integers: “);
gets(s)
printf(“you entered %c”,s); scanf(“%d %d”,&num1,&num2);
getche() sum= num1+num2;
}
printf(“% d= %d”,num1,num2,sum);
return 0;
OPTIONS:
A) geche() and ; }
B) : and getch OPTIONS:
C) getch() and ;
D) clrscr and gets() A) return 0
B) + %d and ;
C) :
Answer: C
D) %d

Answer:B

You might also like