0% found this document useful (0 votes)
202 views16 pages

CODE JAM Round1

The document contains 30 questions related to C programming concepts like loops, functions, arrays, pointers, file handling, exceptions etc. The questions would be asked in an online coding competition called Code Jam - Round 1 to test participants' knowledge of C programming. Detailed answers and explanations are expected from participants for each question.

Uploaded by

Project Tims
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)
202 views16 pages

CODE JAM Round1

The document contains 30 questions related to C programming concepts like loops, functions, arrays, pointers, file handling, exceptions etc. The questions would be asked in an online coding competition called Code Jam - Round 1 to test participants' knowledge of C programming. Detailed answers and explanations are expected from participants for each question.

Uploaded by

Project Tims
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/ 16

CODE JAM- Round 1

Q.1 Give the output of the following:

#include<stdio.h>
int main()
{
printf(5+"Good Morning\n");
return 0;
}

Q.2 Give the output of the following code:

#include<stdio.h>
int main(int argc, char *argv[])
{
int i;
for(i=1; i<argc; i++)
printf("%c", argv[i][0]);
return 0;
}
Q.3 Give the output of the following code:

#include<stdio.h>
int main()
{
enum value{VAL1=0, VAL2, VAL3, VAL4, VAL5} var;
printf("%d\n", sizeof(var));
return 0;
}

Q.4 Find the errors:-

#include<stdio.h>
const char *fun();
int main()
{
*fun() = 'A';
return 0;
}
const char *fun()
{
return "Hello";
}
Q.5 How many times the while loop will get excecuted if a
short int is 2 byte wide?

#include<stdio.h>
int main()
{
int j=1;
while(j <= 255)
{
printf("%c %d\n", j, j);
j++;
}
return 0;
}

Q.6 What will the program retuen after running the


following code?

#include<stdio.h>
int main()
{
extern int a;
printf("%d\n", a);
return 0;
}
int a=20;
Q.7 What will the output of the following code?

#include<stdio.h>
int main()
{
static int a[20];
int i = 0;
a[i] = i ;
printf("%d, %d, %d\n", a[0], a[1], i);
return 0;
}

Q.8 How many times the program will print “IndiaBIX”?

#include<stdio.h>
int main()
{
printf("IndiaBIX");
main();
return 0;
}
Q.9 How will you free the memory allocated by the following
program?

#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4
int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}

Q.10 What is the output of the following program?

void main(){
int a=2;
switch(a)
{
case4: printf("A");
break;
case3: printf("B");
case2: printf("C");
case1: printf("D");
break;
default: printf("E");
}
}
Q.11 What will be printed as the result of the operation
below?

main()
{
char s1[]="Cisco"
char s2[]= "systems";
printf("%s",s1);
}

Q.12 What will be the output when the following code is


executed?

int a=10,b;
b=a++ + ++a;
printf("%d,%d,%d,%d",b,a++,a,++a);

Q.13 What will be the output when the fllowing code is


executed?

void main()
{
int a,b;
a=15; b=25;
a=a+b;
b=a-b;
a=a-b;
printf("%d%d",a,b);
}
Q.14 What will be the output when the following code is
executed?

main()
{
int i;
i = 10;
printf("%d\t",5,6);
printf("%d", i , i++);
}

Q.15 What is the output of the following program?

void main(){
int a,b,c,d;
a=b=c=d=1;
a=++b>1 || ++c>1 && ++d>1;
printf("%d%d%d",a,b,c,d);
}

Q.16 What will be the output of the program?

#include<stdio.h>
int main()
{
printf("India", "BIX\n");
return 0;
}
Q.17 Which of the following statements are correct in the
program given below?

#include<stdio.h>
int main()
{
float a=1.5, b=1.55;
if(a=b)
printf("a and b are equal\n");
else
printf("a and b are not equal\n");
return 0;
}

Q.18 What will be the output of the program?

#include<stdio.h>
int main()
{
int x=55;
printf("%d, %d, %d\n", x<=55, x=40, x>=10);
return 0;
}
Q.19 How many times the program will print “GTU-
TECHFEST”?

#include<stdio.h>
int main()
{
printf("GTU-TECHFEST");
main();
return 0;
}

Q.20 What causes a compiler error?

A. int[ ] scores = {3, 5, 7};


B. int [ ][ ] scores = {2,7,6}, {9,3,45};
C. String cats[ ] = {"Fluffy", "Spot", "Zeus"};
D. boolean results[ ] = new boolean [] {true, false, true};
Q.21 What will be the output when the following code is
executed?

#include<stdio.h>
#include<conio.h>
void main()
{
int a=1,b=2,c;
clrscr();
c=a++ + b;
++b = +a;
printf("%d %d %d ",++a,b,c);
getch();
}

Q.22 From the answer of the above program perform the


following program.

#include<stdio.h>
#include<conio.h>
void main()
{
int a= ?,b=?,c=?;
clrscr();
b=+b + ++a + --c - a++;
printf("%d %d %d ",++a-c,b+b,c- --a);
getch();
}
Q.23 From the above solve further.

#include<stdio.h>
#include<conio.h>
void main()
{
int a=?,b=?,c=-?,i;
clrscr();
for(i=c;i<b; ++i)
{
c++;
b--;
if(i==a)
break;
}
b<c?a=b:a=c;
printf("%d %d %d ",a,b,c);
getch();
}
Q.24 Point out the error in the program.

#include<stdio.h>
#include<stdlib.h>
int main()
{
unsigned char;
FILE *fp;
fp=fopen("trial", "r");
if(!fp)
{
printf("Unable to open file");
exit(1);
}
fclose(fp);
return 0;
}

Q.25 Point out the error in the program.

#include<stdio.h>
int main()
{
char ch;
int i;
scanf("%c", &i);
scanf("%d", &ch);
printf("%c %d", ch, i);
return 0;
}
Q.26 What is the output of the following program?

#include<stdio.h>
/* Assume there is a file called 'file.c' in c:\tc directory. */
int main()
{
FILE *fp;
fp=fopen("c:\tc\file.c", "r");
if(!fp)
printf("Unable to open file.");
fclose(fp);
return 0;
}

Q.27 Point out the error/warning in the program?

#include<stdio.h>
int main()
{
unsigned char ch;
FILE *fp;
fp=fopen("trial", "r");
while((ch = getc(fp))!=EOF)
printf("%c", ch);
fclose(fp);
return 0;
}
Q.28 What will be the output of the program?

try
{
int x = 0;
int y = 5 / x;
}
catch (Exception e)
{
System.out.println("Exception");
}
catch (ArithmeticException ae)
{
System.out.println(" Arithmetic Exception");
}
System.out.println("finished");
Q.29 What will be the output of the program?

public class X
{
public static void main(String [] args)
{
try
{
badMethod();
System.out.print("A");
}
catch (Exception ex)
{
System.out.print("B");
}
finally
{
System.out.print("C");
}
System.out.print("D");
}
public static void badMethod()
{
throw new Error(); /* Line 22 */
}
}
Q.30 What will be the output of the program?

public class RTExcept


{
public static void throwit ()
{
System.out.print("throwit ");
throw new RuntimeException();
}
public static void main(String [] args)
{
try
{
System.out.print("hello ");
throwit();
}
catch (Exception re )
{
System.out.print("caught ");
}
finally
{
System.out.print("finally ");
}
System.out.println("after ");
}
}

****************************************************

You might also like