• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Storage Classes and Type Qualifiers

Question 11

Output of following program C
#include <stdio.h>
int fun(int n)
{
    static int s = 0;
    s = s + n;
    return (s);
}

int main()
{
    int i = 10, x;
    while (i > 0)
    {
        x = fun(i);
        i--;
    }
    printf (\"%d \", x);
    return 0;
}
  • 0
  • 100
  • 110
  • 55

Question 12

Output? (GATE CS 2012) C
#include <stdio.h>
int a, b, c = 0;
void prtFun (void);
int main ()
{
    static int a = 1; /* line 1 */
    prtFun();
    a += 1;
    prtFun();
    printf ( \"\\n %d %d \" , a, b) ;
}
 
void prtFun (void)
{
    static int a = 2; /* line 2 */
    int b = 1;
    a += ++b;
    printf (\" \\n %d %d \" , a, b);
}
  • 3 1
    4 1
    4 2
  • 4 2
    6 1
    6 1
  • 4 2
    6 2
    2 0
  • 3 1
    5 2
    5 2

Question 13

Output? C
#include <stdio.h>
int main()
{
  register int i = 10;
  int *ptr = &i;
  printf(\"%d\", *ptr);
  return 0;
}
  • Prints 10 on all compilers
  • May generate compiler Error
  • Prints 0 on all compilers
  • May generate runtime Error

Question 14

C
#include <stdio.h>
int main()
{
  extern int i;
  printf(\"%d \", i);
  {
       int i = 10;
       printf(\"%d \", i);
  }
}
  • 0 10
  • Compiler Error
  • 0 0
  • 10 10

Question 15

Output? C
#include <stdio.h>

int main(void)
{
    int i = 10;
    const int *ptr = &i;
    *ptr = 100;
    printf(\"i = %d\\n\", i);
    return 0;
}
  • i = 100
  • i = 10
  • Compiler Error
  • Runtime Error

Question 16

C
#include <stdio.h>
char *fun()
{
    static char arr[1024];
    return arr;
}

int main()
{
    char *str = \"geeksforgeeks\";
    strcpy(fun(), str);
    str = fun();
    strcpy(str, \"geeksquiz\");
    printf(\"%s\", fun());
    return 0;
}
  • geeksforgeeks
  • geeksquiz
  • geeksforgeeks geeksquiz
  • Compiler Error

Question 17

Consider the following C function, what is the output? C
#include <stdio.h>
int f(int n)
{
    static int r = 0;
    if (n <= 0) return 1;
    if (n > 3)
    {
        r = n;
        return f(n-2)+2;
    }
    return f(n-1)+r;
}

int main()
{
    printf(\"%d\", f(5));
}
  • 5
  • 7
  • 9
  • 18

Question 18

In the context of C data types, which of the followings is correct?
  • “unsigned long long int” is a valid data type.
  • “long long double” is a valid data type.
  • “unsigned long double” is a valid data type.
  • A), B) and C) all are valid data types.
  • A), B) and C) all are invalid data types.

Question 19

For the following “typedef” in C, pick the best statement C
typedef int INT, *INTPTR, ONEDARR[10], TWODARR[10][10];
  • It will cause compile error because typedef is being used to define multiple aliases of incompatible types in the same statement.
  • “INT x” would define x of type int. Remaining part of the statement would be ignored.
  • “INT x” would define x of type int and “INTPTR y” would define pointer y of type int *. Remaining part of the statement would be ignored.
  • “INT x” would define x of type int. “INTPTR y” would define pointer y of type int *. ONEDARR is an array of 10 int. TWODARR is a 2D array of 10 by 10 int.
  • “INT x” would define x of type int. “INTPTR *y” would define pointer y of type int **. “ONEDARR z” would define z as array of 10 int. “TWODARR t” would define t as array of 10 by 10 int.

Question 20

Which of the followings is correct for a function definition along with storage-class specifier in C language?
  • int fun(auto int arg)
  • int fun(static int arg)
  • int fun(register int arg)
  • int fun(extern int arg)
  • All of the above are correct.

There are 31 questions to complete.

Last Updated :
Take a part in the ongoing discussion