search
Log In

Recent questions tagged go2017-programming-1

4 votes
1 answer
1
Consider the following incomplete C function for reversing a singly linked list. node* reverse(node* trav){ if(trav->next) __________________ else { head -> next = null; head = trav; } return trav; } Here, head is a global pointer pointing to the head of the list and where the head ... reverse(trav->next) -> next = trav; trav->next -> next = trav; trav -> next = trav; trav = reverse(trav->next);
asked Oct 19, 2016 in Programming Arjun 628 views
2 votes
2 answers
2
What will be the output of the following code? #include <stdio.h> #include <string.h> int main() { struct mystruct{ char *name; unsigned int age; }; struct mystruct st1 = {"Ram", 12}; printf("%lu %u", strlen(st1.name), st1.age); } 4 12 3 12 compile error run time error
asked Oct 19, 2016 in Programming Arjun 503 views
7 votes
2 answers
3
int foo(int n) { if(n > 10000) return 1; int sum = 0, i; for( i = 0; i < n; i++) { sum += i; } return sum; } The value returned by the above function is $\Theta\left(n^2\right)$ $\Theta\left(n\right)$ $\Theta\left(1\right)$ $\Omega\left(n^2\right)$
asked Oct 19, 2016 in Programming Arjun 644 views
0 votes
3 answers
4
Which of the following statements is true regarding C language? S1: C is a functional language S2: C is a declarative language S3: C is a procedural language S4: C is a structured language S1, S2 and S3 only S3 and S4 only S2, S3 and S4 only S1, S3 and S4 only
asked Oct 19, 2016 in Programming Arjun 778 views
2 votes
4 answers
5
What will be the output of the following code? #include <stdio.h> int main() { char a = 'A', z = 'Z'; printf("%d", z-a); }
asked Oct 19, 2016 in Programming Arjun 309 views
8 votes
1 answer
6
int foo1(float a) { int b = a; return b/2; } int foo2(double a) { int b = a; return b/2; } int foo3(unsigned int a) { int b = a; return b/2; } Consider the above three C functions and choose the best option given below. ( ... throw compile time error foo2 and foo3 return the same value for all input integer values but not foo1 All 3 functions return different value for some input integer values
asked Oct 19, 2016 in Programming Arjun 771 views
6 votes
4 answers
7
The output of the following C program will be (assume IEEE-754 floating point representation) #include <stdio.h> int main() { float a = 0.25; if(a == 0.25) printf("Hello"); printf(" World"); } Hello World World Compile Error Hello
asked Oct 19, 2016 in Programming Arjun 1.3k views
6 votes
2 answers
8
The value returned by the following function for foo(10) is ____ int foo(int x) { if(x < 1) return 1; int sum = 0; for(int i = 1; i <= x; i++) { sum += foo(x-i); } return sum; }
asked Oct 19, 2016 in Programming Arjun 555 views
5 votes
4 answers
9
Which one among the following definitions of string str could cause problem when passed as the first argument to printf function? char str[] = "Hello World"; char str[12] = "Hello World"; char *str = "Hello World"; char str[] = {'H','e','l','l','o',' ','W','o','r','l','d'};
asked Oct 19, 2016 in Programming Arjun 772 views
1 vote
5 answers
10
The value returned by the following code is _____ int foo() { int a[] = { 10, 20, 30, 40, 50, 60 }; int *p = &a[1] , *q = &a[5] ; return q-p; }
asked Oct 19, 2016 in Programming Arjun 606 views
10 votes
2 answers
11
Which of the following statements is correct? S1: A struct object will always occupy more space than an union object having the same elements. S2: Given an int array Arr and a struct object Str both having same size in memory, Arr[100] and Str[100] always have the same size in memory. Only S1 is correct Only S2 is correct Both S1 and S2 are correct Neither S1 nor S2 is correct
asked Oct 19, 2016 in Programming Arjun 773 views
2 votes
1 answer
12
Arnold is a novice in C and by mistake he typed "intt" for all usage of "int" in a C code. Which of the following statement added at the beginning of the code should fix the issue for him? typedef int intt; typedef intt int; #define intt int; #define intt int 1 and 3 2 and 4 3 and 4 1 and 4
asked Oct 19, 2016 in Programming Arjun 334 views
2 votes
1 answer
13
What is the number of tokens in the below C code? int foo(int i, int j){ return printf(" I do it correctly", i > j); }
asked Oct 19, 2016 in Programming Arjun 417 views
6 votes
3 answers
14
Consider the following two C codes: Code 1 Code 2 char *a = "hello world"; printf(a); char a[] = "hello world"; printf(a); Both are valid C codes Code 1 is valid but not code 2 Code 2 is valid but not code 1 Both codes are not valid in C
asked Oct 19, 2016 in Programming Arjun 592 views
10 votes
1 answer
15
#include <stdio.h> int foo(int a[100]) { return sizeof(a); } int main() { int a[10]; printf("%d", foo(a)); } What will be the output of the above code ignoring any compiler warnings and assuming sizeof(int) as 4 when run on a 64 bit machine?
asked Oct 19, 2016 in Programming Arjun 909 views
9 votes
4 answers
16
Which of the following statements produce a compile time error in C? int a = sizeof 3; *(1000) = 5; int a = 5; ((int)a)++; int b = 5, *a = &b; ((int*)a)++; 1, 2 and 3 2 only 2, 3 and 4 All 4
asked Oct 19, 2016 in Programming Arjun 884 views
5 votes
2 answers
17
void foo(int x) { int *p = &x; *p = x*x; } The above code is supposed to modify any input integer with its square. Which of the following statements regarding the above code is correct? The given code is wrong as C uses call by value and hence ... wrong as it is not returning any value The given code is wrong as it is illegal to access the memory of a parameter variable inside a function
asked Oct 19, 2016 in Programming Arjun 323 views
8 votes
2 answers
18
What is the following function doing? unsigned int foo(unsigned int x) { unsigned int c = sizeof x; c <<= 3; if(x == 0) return c; c--; while(x = x & x-1) c--; return c; } Counting the number of bits in the binary representation of x Counting the number of set bits in the binary representation of x Counting the number of unset bits in the binary representation of x None of the above
asked Oct 19, 2016 in Programming Arjun 699 views
3 votes
4 answers
19
What will be returned by the following function foo when called as foo(10)? int foo(int n) { return n & n | 1; }
asked Oct 19, 2016 in Programming Arjun 594 views
7 votes
2 answers
20
What will be the outout of the following code? #include <stdio.h> int main() { int a = 1, b = 2; int c = a++ || b++; printf("%d %d %d", a, b, c); } 1 2 1 2 3 1 2 2 1 2 2 0
asked Oct 19, 2016 in Programming Arjun 465 views
2 votes
3 answers
21
What will be the output of the following program? #include <stdio.h> void f1(int p1, int *p2, int **p3) { p1 = 20; *p2 = p1; **p3 = *p2; p1 = 10; } int main() { int a = 5, b = 5, *c = &b; f1(a, &b, &c); printf("%d %d %d", a, b, *c); } 5 5 5 5 20 20 10 20 20 20 20 20
asked Oct 19, 2016 in Programming Arjun 324 views
2 votes
2 answers
22
What will be the output of the following C program? #include <stdio.h> int main() { int f1(int,int); int x = 9,n = 3; printf("%d", f1(x, n)); } int f1(int x, int n) { int y = 1,i = 1; for(i = 1;i <= n; i++) y = y * x; return(y); } 27 729 81 Compilation Error
asked Oct 19, 2016 in Programming Arjun 429 views
2 votes
2 answers
23
No. of times '*' will be printed by the following C code is _____ #include<stdio.h> void foo(int x) { switch(x){ case 1: printf("*"); case 2: printf("*"); case 3: printf("*"); default: printf("*"); } } int main() { foo(2.5); }
asked Oct 19, 2016 in Programming Arjun 519 views
4 votes
2 answers
24
What is the output of this program? #include <stdio.h> int main() { char *ptr; char string[] = "Hello 2017"; ptr = string; ptr += 4; printf("%s",++ptr); } Hello 2017 ello 2017 2017 o 2017
asked Oct 19, 2016 in Programming Arjun 244 views
7 votes
2 answers
25
The output for the following C program will be #include <stdio.h> int temp; int new(int t) { static int cal; cal = cal + t; return(cal); } int main() { int t, p; for(t=0; t<=4; t++) p = new(t) + ++temp; printf("%d", p); } 25 20 15 Garbage Value
asked Oct 19, 2016 in Programming Arjun 427 views
5 votes
3 answers
26
The output of the following C program will be _____ #include<stdio.h> #define type int type foo(type b) { return b*b; } #undef type #define type float int main() { float a = foo(1.1); printf("%1.2f", a); }
asked Oct 19, 2016 in Programming Arjun 783 views
9 votes
3 answers
27
Consider the following usage of variable a where b is an appropriate pointer variable. int * b = &a; Which of the following declarations is invalid for a? auto int a; register int a; static int a; const int a; 1 and 2 4 only 2 only 2 and 4
asked Oct 19, 2016 in Programming Arjun 791 views
3 votes
2 answers
28
Consider the following C functions: int f1(int a, int b) { while (a != b) { if(a > b) a = a - b; else b = b - a; } return a; } int f2(int a, int b) { while (b != 0) { int t = b; b = a % b; a = t; } return a ... f1 and f2 return same value for all positive inputs but not f3 For some positive input all 3 functions return different values f2 and f3 return same value for all positive inputs but not f1
asked Oct 19, 2016 in Programming Arjun 700 views
7 votes
8 answers
29
What will be the output of the following code? #include <stdio.h> #include <string.h> int main() { char string[] = "Hello"; if(sizeof(string) <= strlen(string)) printf("1"); printf("0"); } ______
asked Oct 19, 2016 in Programming Arjun 985 views
6 votes
2 answers
30
Consider the following C function: void foo() { int a[10][20][30] = {0}; __________ printf("%d", a[3][4][5]); } Which of the following could be used in the missing line so that the output is 2? a[3][4][5] = 2; *(*(*(a+3) + 4) + 5) = 2; (*(*(a+3) + 4))[5] = 2; *((int*)a + 3 * 20 * 30 + 4 * 30 + 5) = 2; Only 1 and 2 Only 1, 2 and 3 Only 1 1, 2, 3 and 4
asked Oct 19, 2016 in Programming Arjun 546 views
To see more, click for the full list of questions or popular tags.
...