C Programming - Declarations and Initializations - Discussion

Discussion Forum : Declarations and Initializations - General Questions (Q.No. 7)
7.
Which of the following is not user defined data type?
1 :
struct book
{
    char name[10];
    float price;
    int pages;
};
2 :
long int l = 2.35;
3 :
enum day {Sun, Mon, Tue, Wed};
1
2
3
Both 1 and 2
Answer: Option
Explanation:

C data types classification are

  1. Primary data types
    1. int
    2. char
    3. float
    4. double
    5. void
  2. Secondary data types (or) User-defined data type
    1. Array
    2. Pointer
    3. Structure
    4. Union
    5. Enum

So, clearly long int l = 2.35; is not User-defined data type.
(i.e.long int l = 2.35; is the answer.)

Discussion:
48 comments Page 1 of 5.

Saru said:   1 decade ago
@Vineet

We cannot define: char enum day[sun,mon]

But we can give it as follows:
#include<stdio.h>
int main()
{
enum var {var1='a',var2,var3};
enum num {num1=5,num2,num3};
printf("%c %c %c \n",var1,var2,var3);
printf("%d %d %d",num1,num2,num3);
return 0;
}

Where the output will be:

a b c
5 6 7

Because, enum is a user defined data type. It is a data type by itself. So you cannot declare it with a built in data type.

Manas said:   1 decade ago
Primitive types are declaration types and the primitive type is already defined by the java programming language. There are eight primitive types defined in java: int, char, boolean, short, void, long, float, double.

Non primitive types are called java reference types and they have name starting with capital letter. Eg: Integer, Float etc.

Karthick said:   1 decade ago
Structure is the collection of different datatype under the common name, union is similar to structure the difference is. In union we can achieve the memory management ie, only the particular data that we call will occupy memory, enum is already explained above.

Sirajmuneer said:   1 decade ago
We can store list of items in a single name called enum
synatx:
enum(val1,val2,....valn);
compailer assign val1=0,val1=1 and so on
we can assign directly to the value of enum
val1=50,
second value is generally 51 and third is 52 and so on

Pankaj said:   1 decade ago
#include<stdio.h>
int main()
{
enum var {var1,var2,var3};
enum num {num1=5,num2,num3};
printf("%d %d %d \n",var1,var2,var3);
printf("%d %d %d",num1,num2,num3);
return 0;
}

Harsha said:   10 years ago
@Jjjay.

We can write long int as.

Long int i = 2.35.

It is syntactically correct in c lang.

The question is which one is not user defined data type, as long int, int are predefined in c language.

Vidya said:   7 years ago
The struct and enum are the user defined data types but long int is predefined datatype (primary datatype), struct can have related datatypes, and enum which has name and value pair.

Levin max said:   1 decade ago
Primitive data types are already predefined data types as such as int , float,double etc. whereas non primitive data types are created by d users as such as objects in java....

Ragaveni said:   1 decade ago
@Kavitha.

User defined datatypes are defined by user as per user convenience and these are defined by making use of predefined datatypes.

Vinita said:   1 decade ago
@Saru.

Does the value of val and num automatically get incremented?

And if val1 was not initialized what value it would have taken ?


Post your comments here:

Your comments will be displayed after verification.